I notice when i do system update which includes new kernel version, the new version gets installed but the old versions are not remove automatically. My grub list is getting longer by the update!! I have 2.6.32-38 to 2.6.32-45 now. The common practice I’m taught is to just leave 2 versions. The latest and greatest and another one which is the version prior to it. This avoids clutter as well as keep one backup in case the new one fails. So it is necessary to do a cleanup.
For the past few rounds of cleanups, I used the method found in Tux Tweaks. I found it useful and I customize it for myself. Here’s my step by step instruction. I list them down here for my own reference. Copy command and edit as necessary.
1. Check kernel version I am currently running. I want to keep this version as well as the older version as backup.
$ uname -r
2. List all available kernels in my system.
$ ls /boot | grep vmlinuz | cut -d’-‘ -f2,3
2.6.32-38
2.6.32-39
2.6.32-40
2.6.32-41
2.6.32-42
2.6.32-45
3. List the package that are installed relative to the kernel I want to remove. In the command below, I’m listing v2.6.32-38 related packages.
$ dpkg -l | grep ^ii | grep 2.6.32-38 | awk -F’ ‘ ‘{ print $2 }’
linux-headers-2.6.32-38
linux-headers-2.6.32-38-generic
linux-image-2.6.32-38-generic
4. Finally, remove the packages listed by the command above with dpkg, apt-get or aptitude. I’m removing 2.6.32-38 here.
$ sudo aptitude remove linux-headers-2.6.32-38 linux-headers-2.6.32-38-generic linux-image-2.6.32-38-generic
I repeat from step 3 for the next oldest version. Visit Tux Tweaks for more information. There are other methods of removal. What is commonly suggested is to do it through the Synaptic Package Manager. I’m comfortable with these.