Cleanup boot partition on Ubuntu
René Dohmen
September 12, 2016
1 min

If apt-get isn’t functioning because your /boot is at 100%, you’ll need to clean out /boot first. This likely has caught a kernel upgrade in a partial install which means apt has pretty much froze up entirely and will keep telling you to run apt-get -f install even though that command keeps failing.

The cause

With a small boot partition and UnAttended upgrades on; a

The solution

Warning: only use this way of cleaning the boot partition when you tried to solve it first with apt-get itself: e.g.

Then delete unneeded kernels with:

replacing VERSION with the linux kernel versions you want to remove. If that yields an error like:

Then this solution is for you.

List kernels that you can remove

Get the list of kernel images and determine what you can do without. The next command will list all installed kernels .

Remove unneeded/unwanted kernels

Craft a command to delete all files in /boot for kernels that don’t matter to you using brace expansion to keep you sane. Remember to exclude the current and two newest kernel images. Example:

Fix apt

to clean up what’s making apt grumpy about a partial install:

If you run into an error that includes a line like “Internal Error: Could not find image (/boot/vmlinuz-3.13.0-68-generic)”, then run the command

(with your appropriate version).

Finally, sudo apt-get autoremove to clear out the old kernel image packages that have been orphaned by the manual boot clean.

Install updates/upgrades

Optionally: run


to take care of any upgrades that may have backed up while waiting for you to discover the full /boot partition.

Eliminating the root cause

You can turn on autoremoval of unneeded software after you unattended security updates by uncommentng an option in /etc/apt/apt.conf.d/50unattended-upgrades: Look for this line: // Do automatic removal of new unused dependencies after the upgrade // (equivalent to apt-get autoremove) Unattended-Upgrade::Remove-Unused-Dependencies "true";

Then apt-get autoremove is executed after each unattended upgrade.

The alternative

Someone wrote a small python program that does this for you: https://github.com/EvanK/ubuntu-purge-kernels Use at your own risk.

Related Posts

Deploy FastAPI on Amazon Serverless
May 15, 2021
5 min
© 2021, All Rights Reserved.
Powered by formatics

Quick Links

Advertise with usAbout UsContact Us

Social Media