The following is an outline of a process for handling initramfs build failures due to low free space on the /boot partition.
Specifically, this is relevant for Ubuntu systems administrators whom may find themselves unable to use the popular ‘apt-get’ to remove older kernels, in the event new kernel package(s) were pulled in, installation attempted, and then subsequently halted due to low disk space on the partition.
This is a unique chick and egg scenario I have observed on more than one occassion due to overly conservative storage allocations for the boot partition.
"gzip: stdout: No space left on device"
When ‘apt-get’ is invoked, you will observe likely something close to the following:
gzip: stdout: No space left on device
E: mkinitramfs failure cpio 141 gzip 1
update-initramfs: failed for /boot/initrd.img-<version>-generic with 1.
run-parts: /etc/kernel/postinst.d/initramfs-tools exited with return code 1
Check which kernel you’re currently using:
$ uname -r
Remove old files relative to the kernels no longer needed.
Warning: Do not remove files pertaining to the kernel the system is currently running–you may want to fall back to them in an emergency.
Any invokation of the package manager, for instance ‘apt-get dist-upgrade’, should identify that the kernel you are trying to install is in a half-configured state, and invoke the update-initramfs script to kick-off generating a new initramfs image. This will be followed by an update to the bootloader configuration.
$ apt-get dist-upgrade
Setting up linux-image-3.13.0-77-generic (3.13.0-77.121~precise1) ...
update-initramfs: deferring update (hook will be called later)
The link /initrd.img is a dangling linkto /boot/initrd.img-3.13.0-77-generic
vmlinuz(/boot/vmlinuz-3.13.0-77-generic) points to /boot/vmlinuz-3.13.0-77-generic
(/boot/vmlinuz-3.13.0-77-generic) -- doing nothing at /var/lib/dpkg/info/linux-image-3.13.0-77-generic.postinst line 491.
run-parts: executing /etc/kernel/postinst.d/apt-auto-removal 3.13.0-77-generic /boot/vmlinuz-3.13.0-77-generic
run-parts: executing /etc/kernel/postinst.d/initramfs-tools 3.13.0-77-generic /boot/vmlinuz-3.13.0-77-generic
update-initramfs: Generating /boot/initrd.img-3.13.0-77-generic
run-parts: executing /etc/kernel/postinst.d/update-notifier 3.13.0-77-generic /boot/vmlinuz-3.13.0-77-generic
run-parts: executing /etc/kernel/postinst.d/zz-update-grub 3.13.0-77-generic /boot/vmlinuz-3.13.0-77-generic
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-3.13.0-77-generic
Found initrd image: /boot/initrd.img-3.13.0-77-generic
Found memtest86+ image: /memtest86+.bin
Setting up linux-image-generic-lts-trusty (126.96.36.199.69) ...
With disk space freed up on /boot by deleting old kernels no longer needed, the above operation will complete sucessfully.
The deleting of files tied to previously installed kernel packages–files which are supposed to be maintained by the package manager, is naturally, not a recommended practice.
Therefore, it is wise to let dpkg formally know that packages are no longer needed.
Perform the following to locate kernel-related packages. I find the presentation of ‘dpkg -l’ in conjunction with some grep-ing to be much better than “dpkg –get-selections”:
$ dpkg -l 'linux-*' | egrep -v "un" | egrep -i "name|status|=|image|headers|ii"
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Description
ii linux-firmware 1.79.18 Firmware for Linux kernel drivers
ii linux-image-3.13.0-77-generic 3.13.0-77.121~precise1 Linux kernel image for version 3.13.0 on 64 bit x86 SMP
ii linux-image-generic-lts-trusty 188.8.131.52.69 Generic Linux kernel image
ii linux-libc-dev 3.2.0-98.138 Linux Kernel Headers for development
$ apt-get purge linux-image-<version>-generic
If you are the cautious type:
$ update-grub && update-initramfs -u
This is rather unnecessary (see the above terminal data), but they aren’t your electrons, right?