Safely clean your /boot partition

Ever had your Linux /boot partition fill up? Well, unfortunately I have.
Normally, you would just remove the kernels you don’t need anymore. Best way to do this is to first check what kernel version you are currently using:

$ uname -r

Next up is to list all available linux images:

$ sudo dpkg --list 'linux-image*'

The final step would be to remove the linux images you no longer need. Don’t forget by replacing VERSION with the version you don’t need anymore.

sudo apt-get remove linux-image-VERSION

When you’re done remove those kernels, you can then remove the old packages as well and update the grub kernel list:

$ sudo apt-get autoremove
$ sudo update-grub

The only problem is that if your /boot partition is completely full, aptitude will fail. It won’t do the heavy lifting for you. Certainly if it started an install and failed due to unavailable disk space.
So we will need to remove the old images manually.

So we start the same way as we would do above:

$ uname -r
$ sudo dpkg --list 'linux-image*'

We first get the current kernel version and list all the images available.

Start making some space

Then we need remove the installed images manually:

$ sudo rm -rf /boot/*3.13.0-{32,44}-*

The above regex will remove images with version 3.13.0-32 and 3.13.0-44

Now force install the failed kernel so aptitude stops complaining:

$ sudo apt-get -f install

If aptitude is still complaining that it cannot find and image, purge it that image first:

sudo apt-get purge linux-image-3.13.0-32-generic (with your appropriate version).

And then clear out the old kernel image packages:

$ sudo apt-get autoremove

To prevent this from happening in the future, try setting Unattended-Upgrade::Remove-Unused-Dependencies to true in the /etc/apt/apt.conf.d/50unattended-upgrades file. This is the equivalent of running autoremove after each security update to make sure you clean out unused kernels and other packages it thinks are unused.