Fixing grub for dual-boot after 7.10 upgrade

Dan Wieringa
The Geeklimit Archives
5 min readOct 23, 2007

Â

After I upgraded my dual-boot laptop’s Ubuntu from 7.04 to 7.10, I’ve noticed that the upgrade overwrote my GRUB settings, so when I boot my machine, I no longer have a choice for booting into WinXP. I know the partition is still there, because Ubuntu 7.10 comes with NTFS read/write capability, and automatically shows a ‘Windows XP’ drive in my devices.

So how do I restore my pretty GRUB menu, and give myself the option to boot into either WinXP or Ubuntu 7.10? Every once in a while, I have to write an install script for a Windows app, so I do need to set this up…

First of all, let’s have a look at the grub menu file. I click on ‘Places’ in my menu, and go to:

Filesystem/boot/grub/menu.lst

I see the file that gives me my menu when I boot! Now there are a lot of helpful comments here, but if I strip the comments out, I essentially see these basic options:

default 2
timeout 5
color cyan/blue white/blue
### 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=d403f712–7e72–4bc4-af12–0549fbc1624f 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

## should update-grub add savedefault to the default options
## can be true or false
# savedefault=false

## ## End Default Options ##

title Ubuntu 7.10, kernel 2.6.22–14-generic
root (hd0,2)
kernel /boot/vmlinuz-2.6.22–14-generic root=UUID=d403f712–7e72–4bc4-af12–0549fbc1624f 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,2)
kernel /boot/vmlinuz-2.6.22–14-generic root=UUID=d403f712–7e72–4bc4-af12–0549fbc1624f ro single
initrd /boot/initrd.img-2.6.22–14-generic

title Ubuntu 7.10, kernel 2.6.20–15-generic
root (hd0,2)
kernel /boot/vmlinuz-2.6.20–15-generic root=UUID=d403f712–7e72–4bc4-af12–0549fbc1624f ro quiet splash
initrd /boot/initrd.img-2.6.20–15-generic
quiet

title Ubuntu 7.10, kernel 2.6.20–15-generic (recovery mode)
root (hd0,2)
kernel /boot/vmlinuz-2.6.20–15-generic root=UUID=d403f712–7e72–4bc4-af12–0549fbc1624f ro single
initrd /boot/initrd.img-2.6.20–15-generic

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

### END DEBIAN AUTOMAGIC KERNELS LIST

Now that your eyes are glazed over, the important parts are at the top and the bottom. On the bottom of this list, we see the 5 entries that I’m seeing now when my machine boots.

On the top of the list, ‘Default’ says which of the 5 entries will be selected automatically. The entries are always numbered 0, 1, 2, 3, 4… etc. It starts with zero. So the defualt of 2 means that the third choice will be my default. I know, confusing, but that’s how it is.

So no entry here for Windows XP! You can see that the entries have a fairly standard layout though, so let’s put it back in. the grub file already has a helpful guide listed:

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

You can look up more info on GRUB works here, but what I’m most interested in is the ‘root (hd0,0)’ line. What this line says is that the root of whatever entry I’m doing is located on (drivenumber/partition). Since I only have one hard drive, I know my entry has to be something like this:

title Windows XP Professional SP2

root (myharddrive,somenumber)

makeactive

chainloader +1

(That last entry lets GRUB pass off the boot process to Windows’ native booter.)

So if I want to list all the partitions on my hard drive, I can give the console a: sudo fdisk -l

And I get this:

Device Boot Start End Blocks Id System
/dev/sda1 * 1 3823 30708216 7 HPFS/NTFS
/dev/sda2 3824 4119 2377620 f W95 Ext’d (LBA)
/dev/sda3 4120 4864 5984212+ 83 Linux
/dev/sda5 3824 4078 2048256 b W95 FAT32
/dev/sda6 4079 4119 329301 82 Linux swap / Solaris

Well this makes sense… I have my first partition as NTFS, that’s Windows XP. I can see I have a few other partitions, mainly a 2GB FAT32 partition that I use as a play area, and my Linux partitions. I only have one hard drive, so my ‘root’ listing has to be (hd0,xxx). Since I want the first partition, I’ll make it root (hd0,0)

So my entry will be:

title Windows XP Professional SP2

root (hd0,0)

makeactive

chainloader +1

I’ll add that entry in, as well as partition out some of the other entries I don’t use. I’ll also name the Ubuntu menu choice something nicer than ‘Ubuntu 7.10, kernel 2.6.22–14-generic’. Now my choices read:

title      Please choose an Operating System
makeactive

title      — — — — — — — — — — — — — — — — -
makeactive

title      Windows XP Professional SP2
root      (hd0,0)
makeactive
chainloader    +1

title      Ubuntu 7.10 Gutsy Gibbon
root      (hd0,2)
kernel      /boot/vmlinuz-2.6.22–14-generic root=UUID=d403f712–7e72–4bc4-af12–0549fbc1624f ro quiet splash
initrd      /boot/initrd.img-2.6.22–14-generic
quiet

Now one very important thing: my default is still set to ‘2’, which means the title = 0, dotted line = 1, WinXP = 2, and Ubuntu = 3. I changed my default to 3, so Ubuntu automatically boots up. You might want to have WinXP boot, it’s your choice, just get the number right.
Also, if you want a shorter boot time, you can change ‘timeout’ to 5 like me, or leave it on 15 seconds or whatever grub’s default time is.

…and that’s it! When I boot my machine, I get a nice, clean menu that looks like this (except the dotted line is exactly the same width as the ‘Please choose…’ line:

Please choose an Operating System
— — — — — — — — — — — — — — — — -
Windows XP Professional SP2
Ubuntu 7.10 Gutsy Gibbon

Ubuntu is selected by default, and if I don’t do anything for five seconds, Ubuntu boots.

--

--