Fixing Ubuntu Boot Errors
August 04, 2020
I recently had an issue with my Ubuntu 18.04 laptop starting up. It can be daunting to fix startup errors since you do not have access to the terminal to fix anything.
In previous versions of Ubuntu (pre 18.04), you could boot up in recovery mode and run commands from there. In 18.04 the recovery mode has been removed but here is what you can do.
Create a Live USB
For debugging you will have to create a Live USB which will run Ubuntu and allow you to operate on your filesystem. Follow the instructions linked to create the live usb.
Insert the usb and modify the boot order so the BIOS loads from the USB. Entering BIOS is slightly different for each PC type but generally requires pressing F2 during boot time. The rest of the sections will assume you are booted on the live usb.
Using Fsck to auto fix many filesystem errors
Once you are booted up in the live usb, you can use fsck to resolve filesystem corruption errors that could result in Ubuntu failing to load up.
First run fdisk
or gparted
(GUI version) to find the available partitions as shown below.
sudo fdisk -l
Pick the partition that represents your main ubuntu installation, you can tell by the disk size and it may also say “Linux Filesystem” as the type. For example, my partition is /dev/sda2
Run fsck on the partition. The -y flag will automatically resolve any errors that do not require user intervention.
sudo fsck -y /dev/sda2
Viewing main partition information (logs) through Live USB
While using the live usb, you can mount the main ubuntu 18.04 partition to any folder for browsing.
For example, mount /dev/sda2
(ubuntu partition) to ubuntu_filesystem
folder
sudo mount /dev/sda2 ~/Desktop/ubuntu_filesystem
Now that the partition is mounted to a folder, you can browse through the ubuntu_filesystem
folder to search for useful startup log errors.
For example, when I was troubleshooting I found logs showing gdm3 startup failures at var/log/messages
which led me in the right troubleshooting direction.
Operating on the main partition via Live USB
Once you figure out the issue or want to try possible solutions, you may want to operate on the main ubuntu partition (e.g, add or remove packages). By default, the root directory will be the live usb. As a result, any changes made will only affect the usb partition and be lost on reboot. To operate on the main ubuntu partition, this link gives a good overview.
This is a summary of the steps above
mount /dev/sda2 ~/Desktop/ubuntu_filesystem # Mount sda2 filesystemmount --bind /dev ~/Desktop/ubuntu_filesystem/dev # Mount device driversmount --bind /sys ~/Desktop/ubuntu_filesystem/sys # Mount processesmount --bind /proc ~/Desktop/ubuntu_filesystem/proc # Mount sysmount --bind /run ~/Desktop/ubuntu_filesystem/run # Mount run/resolvconf for internet accesschroot ~/Desktop/ubuntu_filesystem # Change root to base off mount point, instead of live usb path. Operations now affect.apt update # Run w/e operations - apt install, apt remove...