Ubuntu - full /boot - Write Error
My Ubuntu /boot filled up, and updates started failing.
I let the installer pick the /boot size, and Ubuntu decides how long to keep old kernels. I could make /boot bigger, but I keep installations standard and treat machines as cattle, not pets. So I clear the space when I hit this. I wrote this note to make things quicker next time.
TL;DR
Everything else failed, so I deleted an old kernel from /boot by hand.
The kernel I need is 6.2.0-26.
$ uname -r
6.2.0-26-generic
I checked /boot, picked an old kernel, and deleted its files:
sudo rm /boot/*-5.19.0-50-generic
After that, apt autoremove worked again.
The whole story
First I tried sudo apt autoremove. It needs free space to run, so it failed instead of helping:
$ sudo apt autoremove
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up initramfs-tools (0.140ubuntu13.4) ...
update-initramfs: deferring update (trigger activated)
Setting up linux-firmware (20220329.git681281e4-0ubuntu3.18) ...
update-initramfs: Generating /boot/initrd.img-6.2.0-26-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/vgubuntu-swap_1)
I: Set the RESUME variable to override this.
zstd: error 25 : Write error : No space left on device (cannot write compressed block)
etc.
Then I checked the installed kernels:
$ dpkg --list 'linux-image-*' | grep '^[a-z]i'
ii linux-image-5.15.0-79-generic 5.15.0-79.86 amd64 Signed kernel image generic
ii linux-image-5.19.0-50-generic 5.19.0-50.50 amd64 Signed kernel image generic
ii linux-image-6.2.0-26-generic 6.2.0-26.26~22.04.1 amd64 Signed kernel image generic
ii linux-image-generic 5.15.0.79.76 amd64 Generic Linux kernel image
ii linux-image-generic-hwe-22.04 6.2.0.26.26~22.04.7 amd64 Generic Linux kernel image
Note: there was also linux-image-5.11.0-27-generic. I didn’t record it, and it’s gone now.
The ii in the first column means the package is marked for install and is installed. The second i is the one that matters here: it shows what is actually installed, so I know what I can remove.
I tried to uninstall an old kernel. That also needs space, so it failed like autoremove did:
jiri@mycroft:/boot$ sudo apt remove --purge linux-image-5.11.0-27-generic
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Is there anything else I can try?
The following packages will be REMOVED:
linux-image-5.11.0-27-generic*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
2 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Do you want to continue? [Y/n] y
Setting up initramfs-tools (0.140ubuntu13.4) ...
update-initramfs: deferring update (trigger activated)
Setting up linux-firmware (20220329.git681281e4-0ubuntu3.18) ...
update-initramfs: Generating /boot/initrd.img-6.2.0-26-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/vgubuntu-swap_1)
I: Set the RESUME variable to override this.
zstd: error 25 : Write error : No space left on device (cannot write compressed block)
So I manually deleted the files for the kernel I didn’t need:
sudo rm /boot/*-5.19.0-50-generic
Then I purged the package, so the filesystem and the package manager agreed again:
$ sudo apt remove --purge linux-image-5.19.0-50-generic
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
linux-image-5.19.0-50-generic*
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 12.3 MB disk space will be freed.
..
..
With the freed space, autoremove worked:
sudo apt autoremove
Finally I updated GRUB, so it knew 5.19.0-50 was gone:
sudo update-grub
It wasn’t necessary, but I also purged every kernel except the running one:
sudo apt purge $(dpkg --list | grep linux-image | awk '{ if ($1=="rc") print $2}' | grep -v '6.2.0-26-generic')
Purge removes the package and its configuration files.