If you’ve had the same Ubuntu installation for a while and have just been upgrading to newer releases, you may have noticed that a lot of older kernel versions are piling up in your grub menu and on your system.
How to remove older kernels from Ubuntu
This can be done by using the Synaptic Package Manager, however I will show you how it is done on the command line.
First, find out what kernel you are currently running:
# uname -a
Linux foogazi 2.6.24-19-generic #1 SMP Wed Jun 18 14:43:41 UTC 2008 i686 GNU/Linux
From the output you can see that you are currently using the 2.6.24-19-generic kernel.
Next, let’s take a look at all of the kernel versions you have installed:
# dpkg -l | grep linux-headers-*
linux-headers-2.6.24-16 2.6.24-16.30 Header files related to Linux kernel version
linux-headers-2.6.24-16-generic 2.6.24-16.30 Linux kernel headers for version 2.6.24 on x
linux-headers-2.6.24-19 2.6.24-19.34 Header files related to Linux kernel version
linux-headers-2.6.24-19-generic 2.6.24-19.34 Linux kernel headers for version 2.6.24 on x
linux-headers-generic 220.127.116.11.21 Generic Linux kernel headers
Now all you need to do is remove the old versions with apt-get. Since we’ve noted with uname -a that we are currently running 2.6.24-19-generic we want to make sure we do not remove it. All of the others can be removed.
# sudo apt-get remove linux-headers-2.6.24-16 linux-headers-2.6.24-16-generic
Now the older kernels are gone. Repeat the apt-get remove step to remove any others you may have. Remember to not remove your current kernel.
Important note: It is a good idea to keep at least one old kernel version around in case anything breaks in your current kernel and you are unable to boot into it. An example would be that you boot into your current kernel but recieve a kernel panic. With an old kernel still available you can reboot the computer and select the older kernel version from the Grub menu and still access your system to find out what is going on.