Troubleshooting a full /boot partition on Ubuntu

A common 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. This can be done using the df command.

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.

Screenshot of Ubuntu system with full boot partition and no space left on device error

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 it know!

Relevant commands in this article

Like to learn more about the commands that were used in this article? Have a look, for some there is also a cheat sheet available.

  • aptcheat sheet
  • df
  • dpkg

Related articles

Like to learn more? Here is a list of articles within the same category or having similar tags.

Feedback

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