Sunday, July 6, 2008

Editing the Grub Loader Menu

You have your computer set up as a dual boot system and the list of menu items keep growing every time there's a kernel update.

You know that annoying look. That screen shows your Microsoft OS, Memtest and several kernel entries along with their recovery mode images.

Here's how to pare down that list.

WARNING!
Not properly following the directions below may cause your system to not boot.
Proceed at your own risk. I will not be responsible for any damages incurred by your inability to follow directions.

We first need to open up the menu list for emitting. To do that open up a terminal window and type in the following;

sudo gedit /boot/grub/menu.lst

Type in your pasword when prompted.

Now your menu list will open with the permissions needed to edit it.

Look for entries in your menu list that look similar to this;

## ## End Default Options ##

title Ubuntu 7.10, kernel 2.6.22-15-generic
root (hd0,0)
kernel /boot/vmlinuz-2.6.22-15-generic root=UUID=15024b26-e9da-497b-8744-ccfd6170eb84 ro quiet splash
initrd /boot/initrd.img-2.6.22-15-generic
quiet

title Ubuntu 7.10, kernel 2.6.22-15-generic (recovery mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.22-15-generic root=UUID=15024b26-e9da-497b-8744-ccfd6170eb84 ro single
initrd /boot/initrd.img-2.6.22-15-generic

title Ubuntu 7.10, kernel 2.6.22-14-generic
root (hd0,0)
kernel /boot/vmlinuz-2.6.22-14-generic root=UUID=15024b26-e9da-497b-8744-ccfd6170eb84 ro quiet splash
initrd /boot/initrd.img-2.6.22-14-generic
quiet

title Ubuntu 7.10, kernel 2.6.22-14-generic (recovery mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.22-14-generic root=UUID=15024b26-e9da-497b-8744-ccfd6170eb84 ro single
initrd /boot/initrd.img-2.6.22-14-generic

title Ubuntu 7.10, kernel 2.6.22-13-generic
root (hd0,0)
kernel /boot/vmlinuz-2.6.22-13-generic root=UUID=15024b26-e9da-497b-8744-ccfd6170eb84 ro quiet splash
initrd /boot/initrd.img-2.6.22-13-generic
quiet

title Ubuntu 7.10, kernel 2.6.22-13-generic (recovery mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.22-13-generic root=UUID=15024b26-e9da-497b-8744-ccfd6170eb84 ro single
initrd /boot/initrd.img-2.6.22-13-generic

title Ubuntu 7.10, memtest86+
root (hd0,0)
kernel /boot/memtest86+.bin
quiet

### END DEBIAN AUTOMAGIC KERNELS LIST

What we need to do is comment out all the older kernels and their recovery mode entries.
I strongly suggest that you keep the 2 newest entries and their recovery mode entries.
Here's how;

In the above example we can see there are 3 kernel entries.
The newest being 2.6.22-15-generic and the oldest being 2.6.22-13-generic
We want to get rid of the 2.6.22-13-generic and the 2.6.22-13-generic (recovery mode) entries from the boot menu.

So we will comment those entries out. To do that we will use the ## characters to do the commenting.

When it's done it should look like this;


## ## End Default Options ##

title Ubuntu 7.10, kernel 2.6.22-15-generic
root (hd0,0)
kernel /boot/vmlinuz-2.6.22-15-generic root=UUID=15024b26-e9da-497b-8744-ccfd6170eb84 ro quiet splash
initrd /boot/initrd.img-2.6.22-15-generic
quiet

title Ubuntu 7.10, kernel 2.6.22-15-generic (recovery mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.22-15-generic root=UUID=15024b26-e9da-497b-8744-ccfd6170eb84 ro single
initrd /boot/initrd.img-2.6.22-15-generic

title Ubuntu 7.10, kernel 2.6.22-14-generic
root (hd0,0)
kernel /boot/vmlinuz-2.6.22-14-generic root=UUID=15024b26-e9da-497b-8744-ccfd6170eb84 ro quiet splash
initrd /boot/initrd.img-2.6.22-14-generic
quiet

title Ubuntu 7.10, kernel 2.6.22-14-generic (recovery mode)
root (hd0,0)
kernel /boot/vmlinuz-2.6.22-14-generic root=UUID=15024b26-e9da-497b-8744-ccfd6170eb84 ro single
initrd /boot/initrd.img-2.6.22-14-generic

##title Ubuntu 7.10, kernel 2.6.22-13-generic
##root (hd0,0)
##kernel /boot/vmlinuz-2.6.22-13-generic ##root=UUID=15024b26-e9da-497b-8744-ccfd6170eb84 ro quiet splash
##initrd /boot/initrd.img-2.6.22-13-generic
##quiet

##title Ubuntu 7.10, kernel 2.6.22-13-generic (recovery mode)
##root (hd0,0)
##kernel /boot/vmlinuz-2.6.22-13-generic ##root=UUID=15024b26-e9da-497b-8744-ccfd6170eb84 ro single
##initrd /boot/initrd.img-2.6.22-13-generic

title Ubuntu 7.10, memtest86+
root (hd0,0)
kernel /boot/memtest86+.bin
quiet

### END DEBIAN AUTOMAGIC KERNELS LIST


As you can see, we put a ## in front of all the entries for the 2.6.22-13-generic kernel.
You need to do this to all the kernel entries older then the newest 2.
That way, should you have a problem with the newest kernel, you can boot into the next oldest one and fix the problem.

Now that we have that cleaned up, let's set the menu so that it doesn't keep adding new kernels to the list that we just cleaned up.

Here's what you need to do.
Look for an entry similar to this in the menu list;

## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
## howmany=7
# howmany=all

We need to edit the last entry that says # howmany=all
Change the =all to =2

It should look something like this;

## controls how many kernels should be put into the menu.lst
## only counts the first occurence of a kernel, not the
## alternative kernel options
## e.g. howmany=all
## howmany=7
# howmany=2


Now your list should never display more then 2 kernel versions along with the recovery mode links.

Close the menu list and select the option to save the changes.

Now for the moment of truth.
Reboot your computer.
If you did everything properly you should only see the 2 newest kernels listed in the grub menu and it will boot up properly when you select the kernel to boot to.

Good luck and enjoy!!!

TaZMAn


No comments: