During routine system maintenance or automated security patching on Ubuntu, package updates can suddenly fail with critical terminal errors: gzip: stdout: No space left on device, E: Write error - write (28: No space left on device), or update-initramfs: failed for /boot/initrd.img. This happens when Ubuntu accumulates redundant, historical Linux kernel images (each comprising vmlinuz, initrd.img, and System.map files) that completely exhaust the storage allocated to the dedicated /boot partition.
When /boot reaches 100% utilisation, standard package managers may refuse to install or remove software. Follow these systematic steps in Ubuntu to purge outdated kernels safely without compromising your active running kernel.
Step 1: Checking Your Active Running Kernel
Before deleting any kernel packages, identify the kernel currently powering your session. Never delete the running kernel:
uname -r
Note down the output version string (for example, 6.8.0-45-generic).
Step 2: Automated Cleanup Using apt autoremove
If the package manager is not completely blocked, Ubuntu’s built-in autoremove command can prune superseded kernels automatically while retaining the active kernel and the immediate previous fallback:
sudo apt autoremove --purge
If this command executes successfully and frees space in /boot, run df -h /boot to confirm disk recovery.
Step 3: Manually Removing Old Kernels When apt is Blocked
If /boot is completely full, apt commands may abort with unmet dependency errors. In this scenario, identify and purge packages directly using low-level dpkg:
- List all installed kernel image packages:
dpkg --list | grep -E "linux-image-[0-9]" - Identify older version numbers that do not match the output from
uname -r. - Purge a specific obsolete kernel package using
dpkg:sudo dpkg --purge linux-image-6.8.0-38-generic linux-modules-6.8.0-38-generic - Repeat for any other obsolete kernel versions until
df -h /bootindicates at least 30% free space.
Step 4: Repairing Package Dependencies and Updating GRUB
Once sufficient disk space is reclaimed in /boot, finish the interrupted package configuration and update the GRUB bootloader menu:
sudo apt-get install -f
sudo update-grub
Your Ubuntu system will now install future security kernels smoothly without risk of bootloader partition exhaustion.