If apt-get isn’t working because your /boot folder is full, you will need to clean out /boot first. This is fairly common and can be mitigated by creating some cron jobs to keep your server up to date, which I will cover in a later post. I made these notes after running into this a couple of times on my own servers, and I hope it helps someone else.

It will keep telling you to run apt-get -f install even though that command will fail every time.

Get the list of kernel images and determine what you can remove. This command will show the installed kernels except the one currently running:

sudo dpkg --list 'linux-image*'|awk '{ if ($1=="ii") print $2}'|grep -v `uname -r`

Note the two newest versions in the list. You don’t need to worry about the running one as it isn’t listed here. You can check that with uname -r

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:

sudo rm -rf /boot/*-3.3.1-{24,42,45,52,53,54,55,56}-*.

You can also use a range with the syntax {80..84}

After removing those kernels, you can run a sudo apt-get -f install to clean up what’s left.

If you get an error that includes a line similar to “Internal Error: Could not find image (/boot/vmlinuz-3.3.1-52-generic)”, then run the command sudo apt-get purge linux-image-3.3.1-52-generic

Lastly, you can run a  sudo apt-get autoremove to clear out the old kernel images that have been left behind from the manual boot clean.

You may also want to run a sudo apt-get update and a sudo apt-get upgrade to take care of any upgrades that may have backed up while waiting for you to clear the full /boot partition.