Pages

December 27, 2010

Clean Up the GRUB2 Menu

I'm on my Christmas break and so I get to use my personal computer most of the time. I am currently using an Ubuntu run netbook and lately I did a kernel upgrade as per advice of the update manager.

I noticed that the Grub menu at the boot screen is presenting me with way too many choices of the different kernels installed and it looks messy (for me). So today, since I am on vacay and I don't have much to do, I decided to try and clean up the Grub menu. This will not only make the Grub menu look cleaner, it will also remove the unused kernels and recover some disk space.

First up, I had to make sure which is the latest kernel installed so I don't accidentally remove that one. So I went to the command line, issued an command and got a result of the latest kernel installed.

ric@ubuntu-nb:~$ uname -r
2.6.32-27-generic

Then I checked what kernels are currently installed.

ric@ubuntu-nb:~$ sudo update-grub2
[sudo] password for ric:
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.32-27-generic
Found initrd image: /boot/initrd.img-2.6.32-27-generic
Found linux image: /boot/vmlinuz-2.6.32-26-generic
Found initrd image: /boot/initrd.img-2.6.32-26-generic
Found linux image: /boot/vmlinuz-2.6.32-25-generic
Found initrd image: /boot/initrd.img-2.6.32-25-generic
Found linux image: /boot/vmlinuz-2.6.32-24-generic
Found initrd image: /boot/initrd.img-2.6.32-24-generic
Found linux image: /boot/vmlinuz-2.6.32-21-generic
Found initrd image: /boot/initrd.img-2.6.32-21-generic
Found memtest86+ image: /memtest86+.bin
Found Microsoft Windows XP Home Edition on /dev/sda1
Found Windows NT/2000/XP on /dev/sda3
done
ric@ubuntu-nb:~$

In my current setup, I have 5 kernels installed. I decided to keep the 2 most recent and remove the other 3.

ric@ubuntu-nb:~$ sudo apt-get remove linux-image-2.6.32-21-generic linux-image-2.6.32-24-generic linux-image-2.6.32-25-generic
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages will be REMOVED:
linux-image-2.6.32-21-generic linux-image-2.6.32-24-generic
linux-image-2.6.32-25-generic
0 upgraded, 0 newly installed, 3 to remove and 0 not upgraded.
After this operation, 295MB disk space will be freed.
Do you want to continue [Y/n]?

In my installation, after the removal of each image, the Grub update script is run. To be sure that the Grub menu is updated, you can run the update-grub2 command again.

ric@ubuntu-nb:~$ sudo update-grub2
Generating grub.cfg ...
Found linux image: /boot/vmlinuz-2.6.32-27-generic
Found initrd image: /boot/initrd.img-2.6.32-27-generic
Found linux image: /boot/vmlinuz-2.6.32-26-generic
Found initrd image: /boot/initrd.img-2.6.32-26-generic
Found memtest86+ image: /memtest86+.bin
Found Microsoft Windows XP Home Edition on /dev/sda1
Found Windows NT/2000/XP on /dev/sda3
done
ric@ubuntu-nb:~$

Notice that the 3 other images have been removed.

GRAPHICAL WAY:

One can also use the Synaptic Package Manager to remove these images. Just go to System » Administration » Synaptic Package Manager. Do a quick search for linux-image and look for the versions you want to remove. It should look like linux-image-[version]-generic in the Package list. Simply click the green box and select "Mark for Complete Removal" from the drop-down menu.

No comments:

Post a Comment