A safe way to clean the boot partition.
Suppose that one day you are routinely performing a maintenance update or wanting to install a new package and suddenly be greeted by the following:
username@ubuntu:~# sudo apt install yourpackage
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:
yourpackage : Depends: libyourpackage1 (>= 1.x.x) but it is not going to be installed
linux-image-virtual : Depends: linux-image-4.x.0-xxx-generic but it is not going to be installed
E: Unmet dependencies. Try 'apt-get -f install' with no packages (or specify a solution).
Problem: /boot/
is 100% full and/or apt
is not working
Check the current version of your kernel
$ uname -r
It will show something similar to the following:
4.4.0-130-generic
List the old kernels
$ dpkg --list 'linux-image*' | awk '{ if ($1=="ii") print $2}' | grep -v `uname -r`
It will show something similar to the following:
linux-image-4.4.0-116-generic
linux-image-4.4.0-121-generic
linux-image-4.4.0-124-generic
linux-image-4.4.0-127-generic
linux-image-4.4.0-128-generic
linux-image-4.4.0-133-generic
linux-image-4.4.0-148-generic
linux-image-virtual
Get ready to craft a remove command to delete the old kernels.
Please be sure to keep the current and the last two versions of the kernel.
$ sudo rm -rf /boot/*-4.4.0-{116,121,124,127,128}-*
Time to cleanup apt
, remove orphaned kernel images, and update grub
$ sudo apt-get -f install ; sudo apt-get autoremove ; sudo update-grub
Finally, you can now update and install packages again!
$ sudo apt-get update