CleanMate

All guides · Ubuntu · Updated

Ubuntu /boot full: remove old kernels safely and get apt working again

Why /boot fills up on Ubuntu (an initrd per kernel), how to list kernels with dpkg -l and uname -r, apt autoremove --purge, removing one kernel by hand, and fixing apt when /boot is already too full to upgrade.

Install on Ubuntu — free and open source

CleanMate for Ubuntu after a scan, listing old kernels, the APT cache and the journal with sizes

If you just want back the space caches take, start with how to clear the cache on Ubuntu. This guide is for the emergency: “The upgrade needs a total of 120 M free space on disk ‘/boot’” or “No space left on device” during apt upgrade: on Ubuntu this almost always means old kernels. Each kernel puts a compressed image (vmlinuz) and an initial RAM disk (initrd.img, often 60 to 120 MB) in /boot, and on many installs /boot is a separate partition of 500 MB to 1 GB. Three or four kernels fill it.

See how full it is and what is in it:

df -h /boot /
ls -lh /boot

Which kernels are installed, which one runs

uname -r                                   # the kernel running now, e.g. 6.8.0-48-generic
dpkg -l 'linux-image-*' | grep '^ii'       # every installed kernel image

Never remove the running kernel. Keep one older kernel as a fallback: if a new kernel does not boot, you pick the older one under Advanced options for Ubuntu in the GRUB menu.

The normal way: apt autoremove

sudo apt-get -s autoremove   # simulate: read the list first
sudo apt autoremove --purge

Ubuntu marks kernels as automatically installed and keeps the running one, the newest one and the one before it. autoremove removes the rest, with their modules and headers. --purge also removes their leftover config. If kernels were installed by hand (a mainline kernel, a pinned linux-image-* package), apt counts them as manual and autoremove leaves them.

Removing one kernel by hand

Find every package of that version, then purge them together:

dpkg -l | grep 6.8.0-45 | awk '/^ii/{print $2}'
sudo apt purge linux-image-6.8.0-45-generic linux-modules-6.8.0-45-generic \
  linux-modules-extra-6.8.0-45-generic linux-headers-6.8.0-45-generic

Read what apt says it will remove before you answer yes. If it wants to remove linux-generic or another meta-package, stop: that package is what brings kernel updates.

When apt is stuck because /boot is already full

When /boot is full, a half-finished kernel install blocks apt, and apt autoremove fails too because apt first wants to finish the broken install. Free a little space by hand, then let apt repair itself:

uname -r                                     # the version you must NOT touch
ls /boot/initrd.img-*
sudo rm /boot/initrd.img-6.8.0-45-generic    # an OLD version, not the running one
sudo apt -f install
sudo apt autoremove --purge

Only delete the initrd.img of an old kernel you are about to remove: it is the biggest file and apt does not need it to remove the package. Never delete files of the running kernel, and don’t touch vmlinuz, grub/ or efi/. After autoremove, run sudo update-grub if the boot menu still lists the removed kernel (apt normally does it).

The rest of the system disk

Once apt works again, the rest of / is usually the apt cache, the systemd journal and old snap revisions. sudo apt clean and sudo journalctl --vacuum-size=100M are the two quick commands; the details, and what else is safe, are in how to clear the cache on Ubuntu, the systemd journal, /var/log and the apt cache and Snap and Flatpak eating disk space.

How CleanMate does it

On Ubuntu (all Ubuntu features), CleanMate shows each item with its size and removes nothing until you confirm:

System items ask for your administrator password. If /boot is so full that apt is already broken, do the manual repair above first: CleanMate uses apt, so it needs apt working. For a developer machine, see also Free up disk space on Ubuntu as a developer. Download CleanMate.

FAQ

How many kernels should I keep? Two: the running one and one older that boots. That is what Ubuntu’s autoremove and CleanMate keep.

Can I make /boot bigger? Only by resizing partitions, which needs a live USB and a backup. Keeping two kernels is easier.

Is sudo apt clean safe? Yes. It only deletes downloaded installers; installed packages don’t change.

Looking for a BleachBit alternative for Ubuntu? See how CleanMate compares, feature by feature.

Skip the commands

Open source — star it on GitHub: CleanMate for Ubuntu

How CleanMate decides what is safe to remove →