Linux  ·  high  ·  Storage, filesystems & NFS

/boot is full and updates fail

Old kernels have filled a small partition, and the package manager cannot install the new one — often leaving the system half-configured.

What you see

apt or dnf fails partway through a kernel update with a write error on /boot, and subsequent package operations refuse to run until it is resolved.

What is actually wrong

A /boot partition of 200–500MB from an older installation, and kernel packages that are never removed automatically.

Codes and articles

No space left on device /bootrun-parts /etc/kernelupdate-initramfs faileddpkg was interruptedgzip: write error

Fixes (2)

Clear old kernels safely on Debian and Ubuntu
Root shell30 minuteshigh risknot reversible

apt. Removing the running kernel makes the machine unbootable, so identify it first.

  1. Find out which kernel is running. Never remove this one.

    Shell
    uname -rdf -h /boot

    Every accident with this fault is the same accident: a for-loop that removes every kernel matching a pattern, including the running one, on a machine that then does not come back from its next reboot.

  2. List installed kernels with the running one marked.

    Shell
    dpkg -l 'linux-image-*' | awk '/^ii/{print $2}' | while read -r k; do  case "$k" in *"$(uname -r)"*) echo "$k   <== RUNNING";; *) echo "$k";; esacdone
  3. Remove one specific old kernel to make room.

    Shell
    sudo apt purge linux-image-5.15.0-71-generic linux-modules-5.15.0-71-generic
  4. With space free, complete the interrupted operation.

    Shell
    sudo dpkg --configure -asudo apt --fix-broken install
  5. Then let autoremove clear the rest, which respects the running and most recent kernels.

    Shell
    sudo apt autoremove --purge
  6. Keep it from recurring by limiting how many are retained.

    Shell
    printf 'Unattended-Upgrade::Remove-Unused-Kernel-Packages "true";\n' | sudo tee /etc/apt/apt.conf.d/99-kernel-cleanup
Confirm it worked/boot has free space, the update completes, and the machine reboots into the new kernel.
Shell
df -h /boot; dpkg -l 'linux-image-*' | grep -c '^ii'
If you need to undo itA removed kernel can be reinstalled from the repository while the machine still boots.
Clear old kernels on the RHEL family
Root shell25 minutesmedium risknot reversible

dnf or yum.

  1. Check what is installed and what is running.

    Shell
    uname -rrpm -q kerneldf -h /boot
  2. Remove old kernels, keeping the configured number. dnf refuses to remove the running one, which makes this considerably safer than the apt equivalent.

    Shell
    sudo dnf remove --oldinstallonly --setopt installonly_limit=2 kernel

    The installonly mechanism is aware of which kernel is booted and will not remove it. This is the supported path and it should be used in preference to removing packages by name.

  3. Set the retention limit permanently.

    Shell
    sudo sed -i 's/^installonly_limit.*/installonly_limit=2/' /etc/dnf/dnf.confgrep installonly /etc/dnf/dnf.conf
  4. Rebuild the boot configuration if entries are stale.

    Shell
    sudo grub2-mkconfig -o /boot/grub2/grub.cfgsudo grubby --info=ALL | grep ^kernel
  5. Complete any interrupted transaction.

    Shell
    sudo dnf historysudo dnf distro-sync
Confirm it worked/boot has space and the boot menu lists the expected kernels.
Shell
df -h /boot; sudo grubby --default-kernel
If you need to undo itReinstall a removed kernel with dnf install kernel-<version>.

Where this stops. This write-up was written and checked by hand. It says what each step changes, how to confirm it worked and how to reverse it, and anything destructive is flagged before you reach it. If it does not match what your machine is doing, search the Support Centre for the exact code or message — and when something needs a person, get in touch.