Background
This post shows how to remove (clean up) old kernels. Old kernels (to me) are defined as kernels that are installed on your system but no longer needed/used.
Details
You can use a package manager (such as synaptic) to remove old kernels, simply search for linux-image or linux-headers that are installed and remove them. Also of importance is to note that you should remove old kernels and headers together as one is not useful without the other in most circumstances.
Removing Headers
The following steps show how to do this via command line. The first step is to get a list of all ‘headers’ that are installed:
dpkg -l linux-headers-\* | grep ii
This should produce result like the following:
|
|
You will obviously want to leave your current headers (you can find this with the ‘uname -a’ command), I also like to leave the previous version just in case there are some issues and I need to boot with it. This means you would remove the ‘linux-headers-2.6.38-8’ and ‘linux-headers-2.6.38-8-generic’ header files, you can do so with the following command:
apt-get remove linux-headers-2.6.38-8 linux-headers-2.6.38-8-generic
Removing Kernel Images
Next, you should remove the corresponding kernels as they are no longer needed. You can find the kernel names with the following command:
dpkg -l linux-image-\* | grep ii
The results should be similar to those listed in the headers output. Remove old kernels with the following command:
apt-get remove linux-image-2.6.38-8-generic
Finally, cleanup your environment by removing any packages the kernel(s) you just removed my have referenced with the ‘autoremove’ feature in apt with the following command:
apt-get autoremove --purge
I also like to do a apt-get autoclean
at this time as well.
Notes
- I recommend leaving your current headers/kernel and the previous version as well in case you need to boot from a different kernel
- I create boot partitions of 120mb size; 2 kernels generally use around 55mb and allow room for a few more without an issue