Ubuntu - full /boot - Write Error
The /boot directory on my Ubuntu got filled and because of that, updates started failing.
I expected Ubuntu to take care of space in the /boot directory. After all, I let Ubuntu to choose the size of /boot when I was installing it and it’s Ubuntu who choses how long to keep old kernels in the /boot.
It would be possible to create /boot bigger during the installation or to enlarge it later, but I prefer to keep my instalations as standard as possible and to treat them more like cattle rather than pets, so I am going to keep making space whenever I run into this problem in the future and I am creating this note to meake it easier next the time.
TLDR
As everything else failed, I had to delete one the of older kernels from the /boot.
The current kernel, the one I need, is 6.2.0-26.
$ uname -r
6.2.0-26-generic
So I checked /boot, selected other kernel and deleted all it’s files:
sudo rm /boot/*-5.19.0-50-generic
After that all things like the autoremove started working.
The whole story
The first thing to try was sudo apt autoremove but as it turned out it needs space to work so instead of solving the problem with lack of space, it just failed:
$ 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 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: I had there also linux-image-5.11.0-27-generic but didn’t note it and now it’s already removed.
The ii in the fist column means that the kernel is supposed to be installed and is installed. It means that the second i is the important one here as I am checking what is installed so that I can uninstall it.
Then I tried to uninstall one of the older kernels, but again, this action also needs space which is why it fails like the 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 deleted the not needed kernel:
sudo rm /boot/*-5.19.0-50-generic
And removed it so that there was no discrepancy between filesystem and package manager:
$ 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.
..
..
Then, with the released space, the autoremove worked:
sudo apt autoremove
And finally, updated GRUB configuration so that it knows what kernels are available or in his case, that 5.19.0-50 isn’t available anymore:
sudo update-grub
And while it wasn’t necessary, I purged all kernels with the excption of the one I am currently using:
sudo apt purge $(dpkg --list | grep linux-image | awk '{ if ($1=="rc") print $2}' | grep -v '6.2.0-26-generic')
The purge not only uninstalls the package but also deletes the associated configuration files.
Again, the ChatGPT helped a lot :-)