June 6, 2008

Edit Your Grub Boot Menu (Linux Friday)

With all Linux distributions come updates, especially with new versions.  Usually these updates consist of security fixes and new versions of core software.  However, every so often new kernels are released.  The Linux kernel is the core of all distributions.  When these are updated, most of the time your Grub boot menu will become cluttered with multiple kernels.  Here is how to edit your Grub boot menu.

To begin, open the boot menu list in your favorite text editor.  The following code will open the list using gedit, with sudo privileges.

sudo gedit /boot/grub/menu.lst

Once the gedit window opens, you will see a text file with lots of information included.  Don’t worry if you don’t understand what some of the text does, most items have comments explaining them.  Any line that begins with a ‘#’ is considered a comment.  Some lines actually have more than one ‘#’.  These are merely comments that are meant to stand out.

Inside this file you can change a lot of settings that control your boot manager.  For example, you can change the default entry, the time to choose a boot entry, the grub colors, and even completely customize the text for each entry.

Change the timeout
Changing this settings allows for more/less time at the boot menu.  The default is set to something fairly high like 25 or 30.  For most people this is more than enough time to choose the correct entry.  Therefore, if you wish to change the timeout to a lower number, such as 5 seconds look around line 19.  This line should read:

timeout     30

Change the “30″ to the timeout value you wish to have.  The numbers are in seconds.  As I said before, usually 5 or 10 seconds is a good value.

Remove old boot entries (Linux kernels): Safest Method
Scroll near the bottom of the menu.lst file.  Here you will find the entries that appear on the boot menu.  Look around line 128 and you should see:

## ## End Default Options ##

The very next line after this should be the first entry on the boot menu.  This first entry is also usually the newest Linux kernel.  To tell which kernel is the newest look at the last number (following the ‘-’).  For example, the newest kernel for Hardy is “2.6.24-17″.  This is slightly newer than the “2.6.24-16″ version that comes with Hardy.

Therefore, you can remove the old versions from the boot menu by placing a ‘#’ at the beginning of each line corresponding to an old kernel.  Here is a copy of my boot menu for comparison:

title        Ubuntu 8.04, kernel 2.6.24-17-generic
root        (hd0,4)
kernel        /vmlinuz-2.6.24-17-generic root=UUID=a049d4fa-84cb-4fac-bed4-082641c201e3 ro quiet splash
initrd        /initrd.img-2.6.24-17-generic
quiet

title        Ubuntu 8.04, kernel 2.6.24-17-generic (recovery mode)
root        (hd0,4)
kernel        /vmlinuz-2.6.24-17-generic root=UUID=a049d4fa-84cb-4fac-bed4-082641c201e3 ro single
initrd        /initrd.img-2.6.24-17-generic

#title        Ubuntu 8.04, kernel 2.6.24-16-generic
#root        (hd0,4)
#kernel        /vmlinuz-2.6.24-16-generic root=UUID=a049d4fa-84cb-4fac-bed4-082641c201e3 ro quiet splash
#initrd        /initrd.img-2.6.24-16-generic
#quiet

#title        Ubuntu 8.04, kernel 2.6.24-16-generic (recovery mode)
#root        (hd0,4)
#kernel        /vmlinuz-2.6.24-16-generic root=UUID=a049d4fa-84cb-4fac-bed4-082641c201e3 ro single
#initrd        /initrd.img-2.6.24-16-generic

title        Ubuntu 8.04, memtest86+
root        (hd0,4)
kernel        /memtest86+.bin
quiet
### END DEBIAN AUTOMAGIC KERNELS LIST

# This is a divider, added to separate the menu items below from the Debian
# ones.
title        Other operating systems:
root

# This entry automatically added by the Debian installer for a non-linux OS
# on /dev/sda1
title        Microsoft Windows XP Professional
root        (hd0,0)
savedefault
makeactive
chainloader    +1

I do NOT recommend deleting the entries for the old kernel versions.  You can do this but if you were to make a mistake and delete part of the wrong line, you will not be able to boot your computer.

Once you have commented out the old kernel versions you boot menu will look more like this (this is merely an example and does not correspond to the sample text above):

Remove old boot entries (Linux kernels): Advanced Method
This is for you advanced users who don’t like to edit text files.  Again, USE WITH CAUTION

To begin, navigate to ‘/boot’ either in the terminal or using nautilus with sudo privileges.  Then, delete all files with the old kernel version in the name.  The easiest way to do this is to look for the name which has the lowest number at the end.

Once you have deleted these files, run the following code in the terminal to automatically update your grub menu:

sudo update-grub

Customize entry titles
If you don’t like how the entries read, you can change them to whatever you want.  To do this, change the line beginning with “title” for each entry.  This also applies to the “Other Operating Systems” line.  Be careful to only change the lines beginning with “title”

Change default boot entry
This will set the entry that you want to boot automatically upon startup.  To do this look around line 14.  This line should read:

default     0

Once you have the boot menu with ONLY the entries you need, change the “0″ to the line number corresponding to the boot entry you want.  In other words, if the entry you want as default appears as the 3rd line in the boot menu, change the “0″ to a “2″ (the first line is line 0).  Therefore, if you want the first entry to be the default, leave it set to “0″.

TIP: IF you want Windows to be your default entry, and there is a separator (“Other Operating Systems”), don’t forget to include this line in your count.

Once you are done editing the menu.lst file, save your changes and reboot your computer.  The Grub boot menu should now be a little easier to read.

Take a look in the menu.lst file for some other settings: password protection, colors, hidden entries, etc.

Written by Eric

 

Looking for something?

Still can't find what you're looking for? Let us know by dropping a comment on a post or email us at admin[at]wlmtips.com!

Archives

All entries, chronologically...

 

 

Check us out!

Some of our other links...

Visit our friends!

A few highly recommended friends...