Linux kernel fails to update

November 18, 2020


Every once in a while a linux kernel update will fail to install with an error like update-initramfs: failed for /boot/initrd.img...


Typically autoremove fixes this but sometimes manually installed packges can cause issues (which was the case for me since I had installed a custom driver).


Here's a trace:


Setting up linux-image-5.4.0-54-generic (5.4.0-54.60) ...
Processing triggers for initramfs-tools (0.136ubuntu6.3) ...
update-initramfs: Generating /boot/initrd.img-5.4.0-53-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/neon--vg-swap_1)
I: Set the RESUME variable to override this.
Error 24 : Write error : cannot write compressed block 
E: mkinitramfs failure cpio 141 lz4 -9 -l 24
update-initramfs: failed for /boot/initrd.img-5.4.0-53-generic with 1.
dpkg: error processing package initramfs-tools (--configure):
 installed initramfs-tools package post-installation script subprocess returned error exit status 1
Processing triggers for linux-image-5.4.0-54-generic (5.4.0-54.60) ...
/etc/kernel/postinst.d/dkms:
 * dkms: running auto installation service for kernel 5.4.0-54-generic
   ...done.
/etc/kernel/postinst.d/initramfs-tools:
update-initramfs: Generating /boot/initrd.img-5.4.0-54-generic
I: The initramfs will attempt to resume from /dev/dm-2
I: (/dev/mapper/neon--vg-swap_1)
I: Set the RESUME variable to override this.
Error 24 : Write error : cannot write compressed block 
E: mkinitramfs failure cpio 141 lz4 -9 -l 24
update-initramfs: failed for /boot/initrd.img-5.4.0-54-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
dpkg: error processing package linux-image-5.4.0-54-generic (--configure):
 installed linux-image-5.4.0-54-generic package post-installation script subprocess returned error exit status 1
Errors were encountered while processing:
 initramfs-tools
 linux-image-5.4.0-54-generic
E: Sub-process /usr/bin/dpkg returned an error code (1)


Note the Error 24 : Write error : cannot write compressed block block part. While the system has over 100 GB free, if we run df -h | grep boot the the boot volume was almost completely full with only 34 MB free.



/dev/nvme0n1p2             705M  620M   34M  95% /boot
/dev/nvme0n1p1             511M   18M  494M   4% /boot/efi


The solution is to manually remove one of the older versions in order to free up some space in the boot partition. To see what they are use:


sudo apt list --installed | grep linux-image


Then find the oldest one and use


sudo apt remove linux-headers-5.4.0-45 linux-headers-5.4.0-45-generic linux-image-5.4.0-45-generic linux-modules-extra-5.4.0-45-generic


To clean the image, modules, and headers. Then it'll have room to install the latest kernel!

Update: See a better approach using autoremove