Refered to The Official Ubuntu BookThe first thing your computer does when you turn it on is read a special place on your hard disk called the master boot record (MBR). The information written there tells the computer what to do next. When you installed Ubuntu, it placed a boot menu on the MBR that lets you choose from which system to boot.
Unfortunately, when you reinstall Windows it will recreate the MBR, not taking into consideration that any other OS may exist and replacing it with an MBR that only boots Windows. This is no good, and you naturally want to be able to replace it with the menu that lets you choose which system to boot.
Grab the CD you used to install Ubuntu on your computer. If you don't have it anymore, download a CD image from www.Ubuntu.com/download, and burn it on a blank CD. If you used the desktop CD to install, you will need to use the alternate install CD with the traditional text mode installer.
Insert the CD in the drive, and restart your computer. It will boot on the CD instead of using the hard disk as usual. Now highlight the Rescue a Broken System line, and press Enter. Select your language and keyboard, and let the installer detect the network (for the computer name, you can leave the default Ubuntu) just like when you installed Ubuntu for the first time.
You will then be presented with a list of available partitions on your hard disks. Don't worry about the first line (/dev/disks/disk0/part1). Start looking at the other lines. You need to remember on which disk and on which partition Ubuntu is installed. Most of the time, you probably have just one disk. If you have Windows installed on it, it is probably located on the first partition of this disk, and Ubuntu should be on the second one. Therefore, you probably want to select /dev/disks/disk1/part2 (then press Enter), unless your situation is more complex.
On the last screen, select the first line Execute a shell in.... You can now enter commands. Start by mounting the disks on your system:
foo@bar:~# mount -a
Now type:
foo@bar:~# df
Look at the list printed on the screen. Search the last column for the single / character, and on the corresponding line look for the first column. It should say something such as /dev/hda2 (the last few characters may be different for you). Now type the following command, and replace /dev/hda with what you have just read, but without the last digit (/dev/hda instead of /dev/hda2 in the above example):
foo@bar:~# grub-install /dev/hda
Wait for the process to finish. It might take a few minutes. About a dozen lines should have appeared on the screen. Check whether you find the text "installation finished." If you do, everything went fine. You can now restart your computer by typing
foo@bar:~# exit
Eject the CD, and then select Reboot the System. Welcome back to Ubuntu!
Labels: Linux