September 7, 2008

This is not another GRUB tutorial. Most of the people are looking for GRUBologies only when it actually traps you in number errors like “GRUB error 15” …sounds familiar ?? This is why you are here !!
A better approach towards GRUB is to troubleshoot some common problems.
I will distribute this blog into small parts, each dealing with a problem statement, and the concepts are highlighted.

I am using Ubuntu as the host Linux system to demonstrate the examples, but this will work good for all the distros; so when i say Ubuntu, I mean Linux in general.
So hold your breath for now..

General Concepts :

1. In the GRUB world, counting starts from 0 and not 1.

So what you get as /dev/sda1 or /dev/hda8 as seen from your OS, is to be called /dev/sda0 and /dev/hda7 respectively in GRUB.

2. GRUB files are stored at the location /boot/grub, and it’s configuration file is /boot/grub/menu.lst (or

/boot/boot/menu.lst in older systems).

3. GRUB works in stages 1, 1.5 (optional) and 2 in order to complete the boot process.

Problem Statement 1 : You installed Ubuntu first on your hard-disk, and now you want to install Windows over it…OR you have a problem in your Windows system on your multi-boot system, and you have to reinstall Windows, keeping Ubuntu intact.

Concepts :

1. Windows has a habit of owning things, and it persists here too. Their stupid bootloader (which cannot recognize most of the filesystems) overwrites the MBR zone without asking for a permission.

2. GRUB instead has an option of being installed on MBR or some other location, which can be communicated from the MBR.

Tools you need :

1. A Live CD (of any distro)
2. The “sudo” power, or its equivalent.
3. fdisk , this is the utility to show all your hard-disk partitions.

Procedure :

1. Boot into the Live CD.
2. Open up a terminal.
3. Type :
sudo grub
4. Then:
find /boot/grub/menu.lst

5. This will get you an output of the location/s where you have your GRUB configuration files. You may get multiple locations, if you have multiple Ubuntus installed; in that case select the most recent one.Let it be /dev/sda7.
6. Type (assuming /dev/sda7 as your output) :
root (hd0,6) (Take care of the spaces)
7. Next:
setup (hd0) ( If you want to install GRUB on your secondary hard-disk, the use hd1..and so on)
8. Exit GRUB :

This procedure will let you boot into Ubuntu now, but “in most cases” you would be unable to boot into Windows, because the file the location of windows in the GRUB configuration file has now changed. You just need to tell GRUB about the new location of Windows.
To do this, type in the terminal :
sudo fdisk -l (see Troubleshooting section, if it doesnt work)
Locate the Windows partition. Let it be /dev/sda9.

Next you have to edit the GRUB configuration files. Look for your Ubuntu partition (in Places -> Computer)and mount it (just double click over the Ubuntu partition). In case you have made a seperate /boot during ubuntu install, you should similarly mount the /boot partition instead of / .
Look into the /boot folder, and navigate to the grub folder, then menu.lst file.
You now know the location of this file ; so open this file from the terminal as root (use sudo).

When you open this file, look for the Windows portion (probably at the end of the file). Now your Windows partition (as i have supposed) is /dev/sda9 , so edit the Windows partition number from /dev/whatever to /dev/sda9.
Since we know GRUB counts from 0 (see General Concepts 1), we have to number our partition as (hd0,8) and NOT (hd0,9).

title Microsoft Windows NT/98/95 and MS-DOS
root (hd0,whatever)
# rootnoverify (hd0,0)
chainloader +1

to :

title Microsoft Windows NT/98/95 and MS-DOS
root (hd0,8)
# rootnoverify (hd0,0)
chainloader +1

Now you can access your Ubuntu as well as Windows partition from the GRUB menu.