This problem started when I was installing Ubuntu updates today, 125 packages were to be updated. I ran sudo apt update
followed by apt list --upgradable
and sudo apt upgrade
on my laptop, then turned to my desktop machine to continue with other work. I noticed the laptop's screen had gone dark, and when I looked, there was a cursor blinking in the upper left corner, nothing else on the screen. I tried switching to a different virtual terminal, but didn't get any response. I hit the power button briefly to see if that would get any response, and the laptop shut down. When I restarted the laptop, it returned to the same blinking cursor screen. This time, however, I was able to get a virtual terminal opened by pressing Ctrl-Alt-F1
and I logged in. I reviewed the list of packages that had been installed with a tech support guy, and he identified the problem as being a bad video driver upgrade, from nvidia-driver-460
to nvidia-driver-470
, and said we had to install nvidia-driver-495
.
When I tried to install the nvidia-driver-495
package, I got an error message saying dpkg
had been interrupted and I needed to run sudo dpkg --configure -a
which looked like it installed everything else that had been pending from the list of 125 packages. I then tried installing nvidia-driver-495
again, but that said it was missing nvidia-driver-510
as a dependency. I then ran sudo apt install
to install nvidia-driver-510
and all of its dependencies. I checked the GUI terminal at Ctrl-Alt-F7
and it still just had the blinking cursor. I then ran sudo apt install nvidia-driver-495
which didn't produce any errors - but I still only had the blinking cursor on the GUI terminal.
I rebooted the laptop, and got
error: can't find command `hwmatch'
error: can't allocate initrd.
Press any key to continue...
followed by a kernel panic. I restarted the laptop and got only the can't allocate initrd
message, again followed by a kernel panic. When I again restarted the laptop, I was offered the GRUB menu, and was able to boot the machine using the previous kernel, 5.13.0-28
.
After some research, I ran sudo update-initramfs -c -k 5.13.0-30-generic
and rebooted the machine - and had the same failure pattern, finally booting back into the -28
kernel to continue. I poked around a bit more, then ran update-grub
, rebooted - and went through the same cycle again.
I tried deleting the -30
kernel files from /boot
, running sudo apt update
which said all of the packages were up to date, running sudo apt remove
to delete all of the -30
files, running update-grub
again - and apt update
kept insisting all of the packages were up to date: It's like it knew it installed a new kernel version, but then failed to notice when it got removed. I rebooted the laptop, which was successful since it was starting the previously working -28
kernel - and apt update
still didn't have a clue about the kernel upgrade. I ran sudo apt-get remove --purge
with the list of -30
files, which only purged the configuration files, since the packages themselves had already been removed - and apt update
remained blissfully ignorant of the new kernel.
I ran apt list --installed | grep linux-image
which listed the two kernels still installed, -27
and -28
. I ran apt-cache search linux-image|grep 13|grep generic
which gave me a short list of kernels that could be installed. I then ran sudo apt-get install linux-headers-5.13.0-30-generic linux-hwe-5.13-headers-5.13.0-30 linux-image-5.13.0-30-generic linux-modules-5.13.0-30-generic linux-modules-extra-5.13.0-30-generic
to reinstall all of the required packages. Part of the output was
/etc/kernel/header_postinst.d/dkms:
* dkms: running auto installation service for kernel 5.13.0-30-generic
Kernel preparation unnecessary for this kernel. Skipping...
which left me wondering if a required step had been passed by. Everything else looked OK, so I rebooted the machine - and got back to
error: can't find command `hwmatch'
error: can't allocate initrd.
and the kernel panics. I was eventually able to sort out the missing hwmatch
problem through another couple of reboots by following advice from https://www.linux.org/threads/error-cant-find-command-hwmatch-during-boot.32618/ - copying /usr/lib/grub/i386-pc/hwmatch.mod
into the /boot/efi/efi/grub
directory I had to create.
One of the things I've noticed is the -30
initrd
image is 50+% larger than the others:
-rw-r--r-- 1 root root 99M Mar 2 16:41 initrd.img-5.13.0-27-generic
-rw-r--r-- 1 root root 99M Mar 2 16:57 initrd.img-5.13.0-28-generic
-rw-r--r-- 1 root root 156M Mar 2 21:41 initrd.img-5.13.0-30-generic
That may be part of the problem, or it may be a consequence of the problem, I'm not sure.
After running sudo apt-get remove --purge
to remove all of the -30
packages again, I ran sudo find / -xdev -name "*5.13.0-30*"
which only returned
/var/cache/apt/archives/linux-headers-5.13.0-30-generic_5.13.0-30.33~20.04.1_amd64.deb
/var/cache/apt/archives/linux-modules-extra-5.13.0-30-generic_5.13.0-30.33~20.04.1_amd64.deb
/var/cache/apt/archives/linux-image-5.13.0-30-generic_5.13.0-30.33~20.04.1_amd64.deb
/var/cache/apt/archives/linux-hwe-5.13-headers-5.13.0-30_5.13.0-30.33~20.04.1_all.deb
/var/cache/apt/archives/linux-modules-5.13.0-30-generic_5.13.0-30.33~20.04.1_amd64.deb
I didn't think those files were the problem, but after unsuccessfully trying to find another reason for the "Kernel preparation unnecessary for this kernel" message, I used find
to delete them. When I ran sudo apt-get install
again, however, I got the same "Kernel preparation unnecessary" message - and rebooting got me back to the error: can't allocate initrd
problem.
I've now removed the -30
kernel again so I don't have to fight with the laptop when I want to reboot it, but I would like to install the new kernel which I'm sure has some security fixes.
What do I need to do to make Ubuntu forget that the -30
kernel was ever installed, so that I can successfully install it into a bootable state?