There isn’t just one way to get out of a crash on Ubuntu or any other Linux system. The circumstances around a crash are always different. That said, there are a couple of tried and true methods that you can use depending on the severity of the issue.
Tip: Here’s how you can boot into recovery mode in Ubuntu.
1. Restart the Wayland Compositor
Most “crashes” on Ubuntu are caused by an unresponsive Wayland daemon. If you’re not familiar, Wayland is the display server that manages the Linux graphical environment. It’s a large piece of software, and it is one of the first things to break down when something goes wrong.
Since Wayland is just a service like any other running on the system, you should be able to stop and restart it. In order to do that, you’re going to need to get to a different console.
There’s a fairly simple way to do that – press Ctrl + Alt + F3. On a Ubuntu system running GNOME, that will get you to a TTY session. It should work with other desktop environments, too. If it doesn’t, try the different function keys. If absolutely nothing happens, try pressing Alt + SysRq + R first. In the event that none of that works, move on to a different method.
Once you’re in the console, you can use it like you would any other terminal. Sign in and try to restart the Wayland server.
sudo systemctl restart gdm
For KDE, you can also restart its Wayland compositor by replacing gdm with “sddm.”
That should restart Wayland, but if it doesn’t, you can try terminating your entire session.
sudo pkill -KILL -u $USER
In case that doesn’t work, try restarting the system.
2. SSH In
This is another solution for an unresponsive Wayland server. Sometimes accessing the console is too much of a pain, or it’s simply not working. In that case, you might still be able to get into the system over your network with SSH. If your Ubuntu install isn’t running SSH, it’s simple enough to install.
sudo apt install ssh
You can jump onto another computer and use SSH to access Ubuntu. Use your username and the IP address of your Ubuntu machine.
Once you’re in, you can use the terminal like you normally would. Again, you can try to restart Wayland.
sudo systemctl restart gdm
If that doesn’t work, try killing the process or restarting the machine.
3. Alt + SysRq + REISUB
It’s not always the Wayland server that locks up a Linux system. It could be a genuine crash of the entire system. Thankfully, the Linux kernel has built-in tools to allow you low-level control of the system in the event everything else goes wrong. These commands are accessible by pressing the combination of Alt and SysRq on your keyboard. That combination of keys tells the Linux kernel to stop listening to just about everything else and pay attention to the user’s input.
To completely bypass the crash and reboot the system, hold Alt + SysRq, then enter the following keys in order: R – E – I – S – U – B. (This is the opposite of the word “BUSIER.”) That combination of keys will steal keyboard control away from Wayland, terminate all processes running on the machine, sync up the data on your hard drives, unmount the drives, and reboot the system. Essentially, it manually simulates the shutdown process.
When your system boots up again, everything should be normal.
4. Chroot from Live CD
What happens if it’s not normal? What if something really bad happened, and the system broke and won’t boot? There’s something that you can try in that situation, too. You’ll need a Ubuntu live USB, so if you don’t already have one, it’s a good idea to have one on hand anyway.
Boot your computer into the live USB. Select “Try Ubuntu” and click “Next.”
Open a new terminal session and create a few directories to work from:
sudo mkdir /media/recovery sudo mkdir /media/recovery/boot
Mount your computer’s partitions in those directories. Check your actual partition labels.
sudo mount /dev/sda2 /media/recovery sudo mount /dev/sda1 /media/recovery/boot
Mount a couple of system directories in the recovery directory structure to make sure everything works properly.
sudo mount -t proc /proc /media/recovery/proc sudo mount --rbind /sys /media/recovery/sys sudo mount --make-rslave /media/recovery/sys sudo mount --rbind /dev /media/recovery/dev sudo mount --make-rslave /media/recovery/dev sudo mount --bind /run /media/recovery/run sudo mount --make-slave /media/recovery/run
Finally, use chroot to change your root directory to your crashed Ubuntu system’s root. This will allow you to actually use the crashed system.
sudo chroot /media/recovery source /etc/profile
Now that you’re in the system, you can try to debug it and find exactly what’s broken. Seeing as you couldn’t boot, restoring the GRUB bootloader would be a good place to start. If you have a broken upgrade, you can also run Apt from here, and it will upgrade your system or repair your package manager.
Again, there isn’t going to be one universal solution from here, but at least you can access your system to figure it out.
In the rare event that your system actually is broken beyond repair, use the live USB to back up your files from your /home directory to an external or networked hard drive. Learn more about some of the best backup software for Linux today.
Image credit: Angry adult woman watching video online on laptop by DepositPhotos. All alterations and screenshots by Ramces Red.
Our latest tutorials delivered straight to your inbox