How to fix or remove a broken kernel (Ubuntu 20.04)

I got a new laptop and installed Ubuntu on it, the touchpad didn't work, so I followed instructions here: IdeaPad 5 15are05 - elan touchpad not working on 20.04 nor on 18.04 and installed a custom configured kernel. So I upgraded from 5.4.0-37-generic to 5.7.5.

My laptop froze and crashed before I could reboot it, and when I restarted it, I got this error message:

out of memory. Press any key to continue...

Then rebooting a second time, I got this error:

Kernel Panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0)

When I go to Advanced Options for Ubuntu and select the 5.7.5 kernel, I got this kernel panic error message. When I boot the 5.4.0-37-generic kernel it works fine.

I hear that this kernel panic issue can be caused by the /boot partition running out of space. Here is what is in my /boot partition:

$ ls -l /boot
total 805492
-rw-r--r-- 1 root root    237718 Tay  20 11:33 config-5.4.0-26-generic
-rw-r--r-- 1 root root    237753 Teg   3 09:24 config-5.4.0-37-generic
-rw-r--r-- 1 root root    242913 Teg  23 20:30 config-5.7.5
drwx------ 2 root root      4096 Sak  31  1969 efi
drwxr-xr-x 4 root root      4096 Teg  23 22:20 grub
lrwxrwxrwx 1 root root        27 Teg  23 17:48 initrd.img -> initrd.img-5.4.0-37-generic
-rw-r--r-- 1 root root  49453383 Teg  23 17:48 initrd.img-5.4.0-26-generic
-rw-r--r-- 1 root root  55362853 Teg  23 20:24 initrd.img-5.4.0-37-generic
-rw-r--r-- 1 root root 668761446 Teg  23 21:19 initrd.img-5.7.5
lrwxrwxrwx 1 root root        27 Teg  23 17:22 initrd.img.old -> initrd.img-5.4.0-26-generic
-rw-r--r-- 1 root root    182704 Kup  13 18:09 memtest86+.bin
-rw-r--r-- 1 root root    184380 Kup  13 18:09 memtest86+.elf
-rw-r--r-- 1 root root    184884 Kup  13 18:09 memtest86+_multiboot.bin
-rw------- 1 root root   4736015 Tay  20 11:33 System.map-5.4.0-26-generic
-rw------- 1 root root   4738082 Teg   3 09:24 System.map-5.4.0-37-generic
-rw-r--r-- 1 root root   5369711 Teg  23 20:30 System.map-5.7.5
lrwxrwxrwx 1 root root        13 Teg  23 20:30 vmlinuz -> vmlinuz-5.7.5
-rw-r--r-- 1 root root  11657976 Tay  22 21:48 vmlinuz-5.4.0-26-generic
-rw------- 1 root root  11662080 Teg   3 10:32 vmlinuz-5.4.0-37-generic
-rw-r--r-- 1 root root  11760704 Teg  23 20:30 vmlinuz-5.7.5
lrwxrwxrwx 1 root root        24 Teg  23 17:48 vmlinuz.old -> vmlinuz-5.4.0-37-generic

I can see that the initrd.img-5.7.5 file is gigantic compared to all the other files in there. Could this be the issue? Why is it so big I wonder.

Google Chrome is the app that caused the laptop to crash.

When I run:

dpkg --list | grep linux-image

the output is:

ii  linux-image-5.4.0-26-generic               5.4.0-26.30                         amd64        Signed kernel image generic
ii  linux-image-5.4.0-37-generic               5.4.0-37.41                         amd64        Signed kernel image generic
ii  linux-image-generic-hwe-20.04              5.4.0.37.40                         amd64        Generic Linux kernel image

It doesn't actually show 5.7.5. But 5.7.5 appears in the Grub menu and it is the default kernel that gets booted.

Is there a way I can repair the 5.7.5 kernel? If not, how can I remove it?


This is how I would do it, assuming that you downloaded and manually installed 5.7.5:

Boot from the oldest kernel, 5.4.0-26-generic, and then remove the 5.7.5 stuff, relink faulty links, reinstall the latest official kernel, update grub and reboot. In your case (but first, for safety, backup your data):

cd /boot
# remove the 5.7.5 stuff
sudo rm config-5.7.5
sudo rm initrd.img-5.7.5
sudo rm System.map-5.7.5

# remove faulty links
sudo rm vmlinuz
sudo rm vmlinuz.old

# Remove faulty kernel
sudo rm vmlinuz-5.7.5

# Relink correctly
sudo ln -s vmlinuz-5.4.0-37-generic vmlinuz
sudo ln -s vmlinuz-5.4.0-26-generic vmlinuz.old

# reinstall the latest official kernel
sudo apt install --reinstall linux-generic

# Make sure grub is OK -- maybe not necessary after reinstall
sudo update-grub

# Make sure nothing else is missing
sudo apt update
sudo apt upgrade  # or sudo apt full-upgrade ## see 'man apt'

# Reboot
sudo reboot now

Should you want to try a 5.7.5 kernel I suggest that you download these packages:

amd64/linux-image-unsigned-5.7.5-050705-generic_5.7.5-050705.202006220832_amd64.deb
amd64/linux-modules-5.7.5-050705-generic_5.7.5-050705.202006220832_amd64.deb

from https://kernel.ubuntu.com/~kernel-ppa/mainline/v5.7.5/ and install them with dpkg, assuming that you have a terminal open in the download directory:

sudo dpkg -i linux-image-unsigned-5.7.5-050705-generic_5.7.5-050705.202006220832_amd64.deb linux-modules-5.7.5-050705-generic_5.7.5-050705.202006220832_amd64.deb

Grub will automatically update and this worked for me, I'm up and running on kernel 5.7.5-generic. If you encounter errors then remove that kernel by booting into an old kernel and then run

sudo apt purge linux-image-unsigned-5.7.5-050705-generic linux-modules-5.7.5-050705-generic

and reboot (grub will be automatically updated).