Troubleshooting a full /boot partition on Ubuntu

A regular issue with systems running Ubuntu is that may fill up the /boot partition. You might have discovered it when running apt, which refused to work. That is unfortunate, as you also need apt to resolve the issue. After trying several options, we found a way to resolve this catch 22, with just three steps. Opposed to other solutions, you don’t need to move files or do other tricky things on your system. Still a word of caution: any tasks you run on your system is your own responsibility. When possible, make backups, snapshots, etc.

The error: Unmet dependencies

Typically you will discover if the unmet dependencies error shows up. For some reason, one package depends on the other. This typically happens overnight, especially if you use a tool like unattended-upgrade for automatic patching.

# apt upgrade
Reading package lists... Done
Building dependency tree 
Reading state information... Done
You might want to run 'apt-get -f install' to correct these.
The following packages have unmet dependencies:
linux-image-extra-4.4.0-93-generic : Depends: linux-image-4.4.0-93-generic but it is not installed
linux-image-generic : Depends: linux-image-4.4.0-93-generic but it is not installed
Recommends: thermald but it is not installed
E: Unmet dependencies. Try using -f.

The first step is to confirm that this issue is really caused by a full /boot partition. Our friendly df command can help here.

df -h /boot

If the usage column shows 100%, then it is full. Time to take the next steps.

Step 1: find and purge kernel packages

The first step is to find all kernel packages, except the one we are running now. This is done with the inner dpkg command. The outer (first) dpkg command then purges the output that we received.

dpkg --purge $(dpkg -l linux-{image,image-extra,headers}-"[0-9]*" | awk '/^ii/{print $2}' | grep -ve "$(uname -r | sed -r 's/-[a-z]+//')")

Tip: run first the dpkg -l command to see what output is returned.

When the command runs, you may still get some errors like no space left on device. That is fine, as that will resolve after a few packages.

Step 2: add missing packages

Now run the suggested apt-get command. Use --yes if you automatically want to answer yes to the related questions asked.

apt --yes -f install

Step 3: remove unneeded packages

Time to clean up by using the autoremove parameter.

apt --yes autoremove

Now your system should have free space again on the /boot partition.

Did this resolve your issue as well? Let us know in the comments.


Small picture of Michael Boelen

This article has been written by our Linux security expert Michael Boelen. With focus on creating high-quality articles and relevant examples, he wants to improve the field of Linux security. No more web full of copy-pasted blog posts.

Discovered outdated information or have a question? Share your thoughts. Thanks for your contribution!

Mastodon icon