Back to Blog

Finding What Filled /boot When a Linux Kernel Update Fails

Christopher 6 min read
linuxpatchingtroubleshooting

A Linux kernel update can fail halfway through when /boot has no room for the new kernel's initrd image. On Debian and Ubuntu the package manager then stops with a dpkg error. This post covers how to read the error, how to find what holds the space on /boot, how to remove old kernels safely on apt and dnf systems, and how to make each initrd smaller.

A recent Level1Techs thread describes a Debian testing machine with a 488 MB /boot partition and initrd images of about 105 MB each. apt upgrade sometimes failed because a second initrd image didn't fit next to the first. df also reported 372 MB used on /boot while du counted 153 MB of files.

Read the error from the failed upgrade

The failure shows up when update-initramfs writes the new image. A Launchpad bug report shows the lines Ubuntu prints when /boot fills during a kernel install.

mv: error writing '/boot/initrd.img-4.4.0-97-generic': No space left on device
update-initramfs: failed for /boot/initrd.img-4.4.0-97-generic with mv returning 1.
dpkg: error processing package initramfs-tools (--configure):
E: Sub-process /usr/bin/dpkg returned an error code (1)

The kernel version in the update-initramfs line is the kernel that didn't finish installing. Note it before removing anything, because that version has to stay.

Find what holds the space on /boot

Check the size and use of the filesystem, then list the files by size.

df -h /boot
ls -lhS /boot | head -20

Each installed kernel leaves a vmlinuz, an initrd.img, a System.map, and a config file in /boot. The initrd images are usually the largest files. Compare what df reports as used with what the files add up to.

sudo du -xsh /boot

When df shows much more used space than du, a process may still hold a deleted file open. The space is freed only when that process closes the file. Files on /boot that are deleted but still open can be listed with lsof.

sudo lsof -a +L1 /boot

Restart the process it lists, or reboot, then run df -h /boot again. If the numbers still disagree with no process listed, check the filesystem with fsck while /boot is unmounted, as the Level1Techs poster did.

List the installed kernels and the running kernel

On Debian and Ubuntu, the running kernel and the installed kernel packages can be listed with uname and dpkg.

uname -r
dpkg -l 'linux-image-*' | grep '^ii'

Never remove the package that matches uname -r. Ubuntu's RemoveOldKernels page marks it "DO NOT REMOVE", together with any kernel shown as iU, which is queued for install. Kernels marked rc are already removed and only their configuration files remain.

Remove old kernels with apt

When apt still runs, let it remove the kernels it no longer needs.

sudo apt autoremove --purge

apt keeps the kernels named in /etc/apt/apt.conf.d/01autoremove-kernels, which include the running kernel and the newest ones. It also only removes kernels that were installed automatically by an upgrade. A kernel installed by hand by its version number stays until you purge it yourself. Read the file to see which versions apt will keep.

cat /etc/apt/apt.conf.d/01autoremove-kernels

When apt can't run because /boot is full

With a kernel install left half-finished, apt can refuse to remove anything until the broken dependency is fixed. Ubuntu's RemoveOldKernels page gives a manual path with dpkg. Pick one old kernel that is neither the running kernel nor the one that failed. Delete its initrd first, then purge the package.

sudo update-initramfs -d -k 6.8.0-45-generic
sudo dpkg --purge linux-image-6.8.0-45-generic
sudo apt-get -f install

Replace 6.8.0-45-generic with the old version from your dpkg -l list. If dpkg --purge fails, its output names the package that depends on that kernel (a linux-modules-extra or linux-image-extra package, for example). Purge that package in the same command. apt-get -f install finishes the interrupted kernel install. If it fails again for space, purge one more old kernel the same way.

Fedora, RHEL, and other dnf systems

dnf keeps a set number of kernels, set by installonly_limit in /etc/dnf/dnf.conf. The dnf5.conf manual gives a default of 3 and a minimum of 2. Remove the kernels above that limit with dnf. The dnf5 remove manual says the running kernel is skipped.

sudo dnf remove --oldinstallonly kernel

On a /boot that only fits two kernels, set installonly_limit=2 in /etc/dnf/dnf.conf so the next update removes the oldest kernel before space runs out.

Make each initrd smaller on Debian and Ubuntu

The size of each initrd comes from MODULES in /etc/initramfs-tools/initramfs.conf. The initramfs.conf manual says the default, most, adds most file system, ATA, SATA, SCSI, and USB drivers. dep tries to guess which modules the running machine needs and adds only those. Set MODULES=dep in that file and rebuild the images for every installed kernel.

sudo update-initramfs -u -k all
ls -lh /boot/initrd.img-*

An image built with dep holds the drivers for this machine only, so keep most on a disk that may move to different hardware.

Confirm the fix

Run df -h /boot and check that the free space is larger than one initrd image. Run sudo apt upgrade or sudo dnf upgrade again and check that it finishes without a dpkg or update-initramfs error. Reboot and check that uname -r shows the new kernel. If it does, the old kernel it replaced can be removed at the next cleanup.

Where ET Ducky shows it

I build ET Ducky. You can open a Live Session shell to the server from the browser without the need for a VPN and run the df, dpkg, and apt commands there. ET Ducky's Linux patching goes through apt, dnf, zypper, snap, and flatpak with rollout rings. You'd tag one server as the first ring and schedule kernel updates to that tag before the rest of the fleet.

Try it on one server

One Windows or Linux server costs $5 a month with no query subscription.

See pricing