Remove old Kernels from Ubuntu

If you are reading this you have probably been using Ubuntu for a while, updating it quite regularly. You mostly likely use GRUB (www.gnu.org/software/grub/) to handle a dual boot, because on your computer you have a Dual Boot or simply you use GRUB to handle your start-up, because Ubuntu keeps old kernels and you never know if the newest one will crash your machine or work perfectly. That’s a nice feature because it brings you stability and choice, but after a while it may get useless and totally superfluous.

After a while, you can end up with many entries in your GRUB menu and you maybe dislike this situation. The solution is very simple. Here are the steps you have to follow in order to clean up you GRUB menu and remove your old kernels for your computer:

  1. Open a terminal and type uname -r. This will show you which kernel you are actually using. If you boot your system normally, like 99,9% of the users do, you will be using the newest kernel, let’s say¬† 2.6.24-23-generic.
  2. OK, now you know that you need to keep 2.6.24-23-generic. As I mentioned above, is a good thing not to remove the last two kernels, expecially if the one you are using is very new (ex: you downloaded it today).
  3. Open Synaptic (System->Administrator-> Package Manager Synaptic). Use the search button and search for linux-image-2. This will show you all the package named linux-image-2* where * means “something”. Some of these packages will have a GREEN box at the beginning of the corresponding row, some will have a WHITE box. The green box tells you that the package on that row is installed in your system. I think you can guess alone what the white box means…
  4. Among all the installed packages, locate your current kernel, ex: 2.6.24-23-generic. This is the package you do not want to remove. As we said above, we want to keep another version. So, starting from the row of your actual kernel, go upwards and find the newest version which was installed before the actual one you are using. For example: 2.6.24-22-generic.
  5. Now you want to uninstall everything which is not 2.6.24-23-generic or 2.6.24-22-generic. So, locate all the other GREEN boxes, representing older kernels, click with the right button of your mouse on the corresponding line an select Mark for removal. The line will get very RED, telling you that it will be removed. Repeat this option for all the other old kernels you do not want to keep;
  6. Once you are done, simply click on the apply button. Synaptic will remove all the old kernels you do not need anymore, giving you some more free space on your disk and cleaning the GRUB menu. Yes, the GRUB menu should update automatically.

In case for some reason, after rebooting your system, the GRUB menu did not change, you can manually edit the configuration file. Open a terminal and type:

sudo gedit /boot/grub/menu.lst

scrolling down this file will show you your menu. It is quite intuitive so I do not explain how it looks like. Simply remove the rows referring to the OLD kernels, remembering not to remove the new ones. Once you are done, click on save and reboot your system.

This should clean up both your hard disk and your GRUB menu from old kernels you do not need anymore. Hope this helps.

Advertisements
Remove old Kernels from Ubuntu