Appendix C - GRUB Boot Menu


This Appendix deals with editing the menu list using GEdit and comprises the following sections :-

Manually editing the Boot Menu (menu.lst file)

By default the grub (boot) menu will take you into Ubuntu when it times out.  If you would prefer to boot into windows by default and/or not always boot into the latest Ubuntu installation, there are 3 ways to change the menu list.
Firstly make a backup of the Grub boot menu in case of an error preventing the computer booting (the menu can then be restored using Live CD).  The code below shows changing to the grub directory, making a copy of the menu to a backup file and then opening the menu.lst file in a text editor in root user mode (sudo).

cd /boot/grub
sudo cp /boot/grub/menu.lst /boot/grub/menu.lst_backup
gksudo gedit /boot/grub/menu.lst

After editing don't forget to save the changes and exit gedit.

Here is a sample menu.lst to illustrate the various methods.  This is the menu.lst from my laptop, which has 4 partitions.  First is a hidden Windows recovery partition, then the main Windows partition, and finally Ubuntu system and swap.  These are all on one physical HD.  Thus we have hd0,1 as Windows (rather than their example of hd0,0) and Ubuntu is hd0,2

# menu.lst - See: grub(8), info grub, update-grub(8)
# grub-install(8), grub-floppy(8),
# grub-md5-crypt, /usr/share/doc/grub
# and /usr/share/doc/grub-doc/.

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not change this entry to 'saved' or your
# array will desync and will not let you boot your system.
default 0

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout 10

## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
#hiddenmenu

# Pretty colours
#color cyan/blue white/blue

## password ['--md5'] passwd
# If used in the first section of a menu file, disable all interactive editing
# control (menu entry editor and command-line) and entries protected by the
# command 'lock'
# e.g. password topsecret
# password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
# password topsecret

#
# examples
#
# title Windows 95/98/NT/2000
# root (hd0,0)
# makeactive
# chainloader +1
#
# title Linux
# root (hd0,1)
# kernel /vmlinuz root=/dev/hda2 ro
#

#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below


## DO NOT UNCOMMENT THEM, Just edit them to your needs

## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
## kopt_2_6_8=root=/dev/hdc1 ro
## kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=UUID=73dfae7e-f4c6-40f2-901c-11396e57ce3e ro

## Setup crashdump menu entries
## e.g. crashdump=1
# crashdump=0

## default grub root device
## e.g. groot=(hd0,0)
# groot=(hd0,2)

## should update-grub create alternative automagic boot options
## e.g. alternative=true
## alternative=false
# alternative=true

## should update-grub lock alternative automagic boot options
## e.g. lockalternative=true
## lockalternative=false
# lockalternative=false

## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=quiet splash

## should update-grub lock old automagic boot options
## e.g. lockold=false
## lockold=true
# lockold=false

## Xen hypervisor options to use with the default Xen boot option
# xenhopt=

## Xen Linux kernel options to use with the default Xen boot option
# xenkopt=console=tty0

## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
## altoptions=(recovery) single
# altoptions=(recovery mode) single

## 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

## should update-grub create memtest86 boot option
## e.g. memtest86=true
## memtest86=false
# memtest86=true

## should update-grub adjust the value of the default booted system
## can be true or false
# updatedefaultentry=false

## ## End Default Options ##

title Ubuntu, kernel 2.6.20-16-generic
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-16-generic root=UUID=73dfae7e-f4c6-40f2-901c-11396e57ce3e ro quiet splash
initrd /boot/initrd.img-2.6.20-16-generic
quiet
savedefault

title Ubuntu, kernel 2.6.20-16-generic (recovery mode)
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-16-generic root=UUID=73dfae7e-f4c6-40f2-901c-11396e57ce3e ro single
initrd /boot/initrd.img-2.6.20-16-generic

title Ubuntu, memtest86+
root (hd0,2)
kernel /boot/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/hda2
title Microsoft Windows XP Home Edition
root (hd0,1)
savedefault
makeactive
chainloader +1

This is controlled by the default parameter - highlighted in yellow above.  The boot point is deternined by the title lines - highlighted in green above - with counting starting at 0 (as explained in the sample text).

Count to the title line you want to boot by default and change the 0 (zero) to that number.  4 in this case.   0 is Ubuntu. 1 is Ubuntu (recovery mode) 2 is memory test 3 is the divider between Ubuntu and other operating systems and 4 is Windows XP.

Thus to boot Windows by default change default 0 to default 4.

NOTE however,
that when an update to the kernal occurs, the new kernel will be added at the top.  This means that the Windows boot line will no longer be 4 but 6 (the new kernel and its recovery mode being added).  Two ways round this - one is covered below - Move Windows entry to the top - but there is another way...

Change the entry #updatedefaultentry=false to #updatedefaultentry=true this is just above ## ## End Default Options ## and highlighted in pink in the sample menu.lst above. Self explanatory really.  Move the Windows boot entry in it's entirety above BEGIN AUTOMAGIC KERNELS LIST - as shown in menu.lst above by the light blue highlighter.  Reason... Anything above the BEGIN DEBIAN AUTOMAGIC KERNELS LIST is not touched and the Windows entry may be moved to here.

title Microsoft Windows XP Home Edition
root (hd0,1)
savedefault
makeactive
chainloader +1

A further alternative is to make the boot menu save the identity of the system booted and boot that by default next time.  Simply replace the number in the default option by saved - ie. default saved.  The savedefault line in the boot entries saves the boot ID for this purpose.

Finally
When editing is finished save back and exit gedit.

Addendum...
This next menu.lst shows the effect of an extra 3 kernel updates and the corresponding entries.  These newer entries are highlighted in light blue.

# menu.lst - See: grub(8), info grub, update-grub(8)
# grub-install(8), grub-floppy(8),
# grub-md5-crypt, /usr/share/doc/grub
# and /usr/share/doc/grub-doc/.

## default num
# Set the default entry to the entry number NUM. Numbering starts from 0, and
# the entry number 0 is the default if the command is not used.
#
# You can specify 'saved' instead of a number. In this case, the default entry
# is the entry saved with the command 'savedefault'.
# WARNING: If you are using dmraid do not change this entry to 'saved' or your
# array will desync and will not let you boot your system.
default 0

## timeout sec
# Set a timeout, in SEC seconds, before automatically booting the default entry
# (normally the first entry defined).
timeout 10

## hiddenmenu
# Hides the menu by default (press ESC to see the menu)
#hiddenmenu

# Pretty colours
#color cyan/blue white/blue

## password ['--md5'] passwd
# If used in the first section of a menu file, disable all interactive editing
# control (menu entry editor and command-line) and entries protected by the
# command 'lock'
# e.g. password topsecret
# password --md5 $1$gLhU0/$aW78kHK1QfV3P2b2znUoe/
# password topsecret

#
# examples
#
# title Windows 95/98/NT/2000
# root (hd0,0)
# makeactive
# chainloader +1
#
# title Linux
# root (hd0,1)
# kernel /vmlinuz root=/dev/hda2 ro
#

#
# Put static boot stanzas before and/or after AUTOMAGIC KERNEL LIST

### BEGIN AUTOMAGIC KERNELS LIST
## lines between the AUTOMAGIC KERNELS LIST markers will be modified
## by the debian update-grub script except for the default options below

## DO NOT UNCOMMENT THEM, Just edit them to your needs

## ## Start Default Options ##
## default kernel options
## default kernel options for automagic boot options
## If you want special options for specific kernels use kopt_x_y_z
## where x.y.z is kernel version. Minor versions can be omitted.
## e.g. kopt=root=/dev/hda1 ro
## kopt_2_6_8=root=/dev/hdc1 ro
## kopt_2_6_8_2_686=root=/dev/hdc2 ro
# kopt=root=UUID=73dfae7e-f4c6-40f2-901c-11396e57ce3e ro

## Setup crashdump menu entries
## e.g. crashdump=1
# crashdump=0

## default grub root device
## e.g. groot=(hd0,0)
# groot=(hd0,2)

## should update-grub create alternative automagic boot options
## e.g. alternative=true
## alternative=false
# alternative=true

## should update-grub lock alternative automagic boot options
## e.g. lockalternative=true
## lockalternative=false
# lockalternative=false

## additional options to use with the default boot option, but not with the
## alternatives
## e.g. defoptions=vga=791 resume=/dev/hda5
# defoptions=quiet splash

## should update-grub lock old automagic boot options
## e.g. lockold=false
## lockold=true
# lockold=false

## Xen hypervisor options to use with the default Xen boot option
# xenhopt=

## Xen Linux kernel options to use with the default Xen boot option
# xenkopt=console=tty0

## altoption boot targets option
## multiple altoptions lines are allowed
## e.g. altoptions=(extra menu suffix) extra boot options
## altoptions=(recovery) single
# altoptions=(recovery mode) single

## 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

## should update-grub create memtest86 boot option
## e.g. memtest86=true
## memtest86=false
# memtest86=true

## should update-grub adjust the value of the default booted system
## can be true or false
# updatedefaultentry=false

## ## End Default Options ##

title Ubuntu, kernel 2.6.20-16-generic
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-16-generic root=UUID=73dfae7e-f4c6-40f2-901c-11396e57ce3e ro quiet splash
initrd /boot/initrd.img-2.6.20-16-generic
quiet
savedefault

title Ubuntu, kernel 2.6.20-16-generic (recovery mode)
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-16-generic root=UUID=73dfae7e-f4c6-40f2-901c-11396e57ce3e ro single
initrd /boot/initrd.img-2.6.20-16-generic

title Ubuntu, kernel 2.6.20-15-generic
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-15-generic root=UUID=73dfae7e-f4c6-40f2-901c-11396e57ce3e ro quiet splash
initrd /boot/initrd.img-2.6.20-15-generic
quiet
savedefault

title Ubuntu, kernel 2.6.20-15-generic (recovery mode)
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-15-generic root=UUID=73dfae7e-f4c6-40f2-901c-11396e57ce3e ro single
initrd /boot/initrd.img-2.6.20-15-generic

title Ubuntu, kernel 2.6.20-14-generic
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-14-generic root=UUID=73dfae7e-f4c6-40f2-901c-11396e57ce3e ro quiet splash
initrd /boot/initrd.img-2.6.20-14-generic
quiet
savedefault

title Ubuntu, kernel 2.6.20-14-generic (recovery mode)
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-14-generic root=UUID=73dfae7e-f4c6-40f2-901c-11396e57ce3e ro single
initrd /boot/initrd.img-2.6.20-14-generic

title Ubuntu, kernel 2.6.20-12-generic
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-12-generic root=UUID=73dfae7e-f4c6-40f2-901c-11396e57ce3e ro quiet splash
initrd /boot/initrd.img-2.6.20-12-generic
quiet
savedefault

title Ubuntu, kernel 2.6.20-12-generic (recovery mode)
root (hd0,2)
kernel /boot/vmlinuz-2.6.20-12-generic root=UUID=73dfae7e-f4c6-40f2-901c-11396e57ce3e ro single
initrd /boot/initrd.img-2.6.20-12-generic

title Ubuntu, memtest86+
root (hd0,2)
kernel /boot/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/hda2
title Microsoft Windows XP Home Edition
root (hd0,1)
savedefault
makeactive
chainloader +1


Multiple Ubuntu systems on one computer 

Overview

Where there are two or more Ubuntu systems on one computer, this allows the user to have individual menu.lst files for each system rather than one main one with multiple entries - with only the latest installation updating the working GRUB menu.lst.  With the new arrangement individual kernels can update their own GRUB menu.

The usual problem with multiple systems is that only the last installation's menu.lst will get updated, leaving the menu pointing to an out-of-date kernel.  When each new Ubuntu system is installed the MBR is set to point to the menu.lst in the newly set up partition and any previous menu.lst is then ignored (together with the name of the new kernel).

A nice side effect of changing the grub menu.lst in the way about to be described is that the main menu (on startup) is much tidier and easier to understand.

One method is to use the GRUB command chainloader as is used to transfer control to Windows when that is booted but a simpler method for Ubuntu is to use the configfile GRUB command to point directly to the appropriate menu.lst.

Using the GRUB command configfile

We will replace all entries for a previously installed version with a pointer to it's own menu.lst file.  This uses just two lines..
  1. The title
  2. A link to the other version's menu.lst
For example the entries for Ubuntu Studio
title        Ubuntu 8.04, kernel 2.6.24-18-rt
root        (hd1,1)
kernel      /boot/vmlinuz-2.6.24-18-rt root=UUID=90f71b54-c514-4ea5-8091-177561073883 ro quiet splash
initrd       /boot/initrd.img-2.6.24-18-rt
quiet
title        Ubuntu 8.04, kernel 2.6.24-18-rt (recovery mode)
root        (hd1,1)
kernel      /boot/vmlinuz-2.6.24-18-rt root=UUID=90f71b54-c514-4ea5-8091-177561073883 ro single
initrd       /boot/initrd.img-2.6.24-18-rt
title        Ubuntu 8.04, memtest86+
root        (hd1,1)
kernel     /boot/memtest86+.bin
quiet
May be replaced with
title           Ubuntu Studio
configfile  (hd1,1)/boot/grub/menu.lst
That will redirect menu control to the boot menu in the second partition of the second HD - (hd1,1)  (Note, numbering starts at 0 in this case).  Thus when the user chooses "Ubuntu Studio" in the menu they will then get the menu for Ubuntu Studio which is what's updated when a kernel is replaced with a new version and "update-grub" runs.  Since the new kernel is placed at the top of the list, this is the one that's run by default.  The timeout may be reduced in Studio's menu.lst if desired.

Further simplifying the boot menu

The above method may be used with other menu entries relating to other previously installed Linux systems.  This will still leave multiple stanzas for updates (and the recovery version) for the current (last) install.  To tidy up the main menu still further these entries could do with replacing with the two line configfile setup.  However, if the entries were to be replaced "as is", we would have no valid menu.lst for the last installation.  So we first need to make a copy of the current menu.lst with a different name such as menu1.lst, remove references to the older versions (if desired) and then edit the original menu.lst as above with configfile pointing to the new (copied and renamed) menu1.lst.

The result of all of the above on one of my computers running three versions of Ubuntu plus Windows XP and memtest now looks like this :-
default 0
timeout 8
color yellow/blue yellow/red

title Ubuntu Hardy
configfile   (hd1,8)/boot/grub/menu.lst

title Ubuntu-Studio Hardy
configfile   (hd1,1)/boot/grub/menu.lst

title Ubuntu Intrepid (development)
configfile (hd1,7)/boot/grub/menu1.lst

title Microsoft Windows XP Home Edition
root (hd0,0)
chainloader +1
savedefault
makeactive

title Memory Test
root (hd1,8)
kernel /boot/memtest86+.bin
savedefault

This results in a nice tidy menu with just five lines :-
Ubuntu Hardy
Ubuntu-Studio Hardy
Ubuntu Intrepid (development)
Microsoft Windows XP Home Edition
Memory Test
NOTE:-  QGRUBEditor will no longer work with the main menu - it doesn't understand configfile and will destroy the menu.  However, QGRUBEditor can be used to edit the sub menus in their own partitions (though bear in mind that the last install's menu is now called menu1.lst and the default will need changing in QGRUBEditor).

Note for version 9.04 (Jaunty Jackalope):-  QGRUBEditor is currently not in the Jaunty repositories and may not work with any sub menus for this version.

Updated 26 April 2009