Remove Old Kernels

You are here:
< Back

One of the things that I struggled with on my Ubuntu based web servers was the size of /boot partition and updating.  When I was updating the kernels, the old ones were not removed.  Over time this caused the /boot partition to fill up as it is pretty small to begin with and when it was full, that is when the errors started.

While I am not sure why the /boot partition was made this way and at this size (I am guessing it has to do with creating LVM volumes) I do have a quick and relatively simple way to clean up these old kernels and prevent the /boot partition from filling up.

Open a terminal and check the current kernel:

uname -r

WARNING:  Do not remove this kernel!  This is the kernel in use by the system and removal will cause start-up issues.

Next, the command below will list all installed kernels on your system.

dpkg --list | grep linux-image

Identify all the kernels that lower that your current kernel. When you know which kernel to remove, continue below to remove it. Run the commands below to remove the kernel you selected.

sudo apt-get purge linux-image-x.x.x.x-generic

The command below may not be required by all versions / systems, but if you want to be sure the grub configuration is updated with the changes, run the command below to update grub2

sudo update-grub2

Reboot the system.  A couple of things to note at this point:

  • The System should successfully boot
  • The grub menu should only list the kernel(s) you didn’t remove

It may also be a good idea to check the logs to verify no issues were encountered during start-up.

This process can be found all over on the Internet, so giving any one person source credit wouldn’t really be fair.  I did use Ubuntu sources in the documenting of this process.  This is solely for my reference, if it helps anyone else great.  I don’t claim to understand your system and if anything catastrophic happens by following these instructions I take no responsibility, these instructions are use at your own risk.

Last Updated On October 24, 2017