Thursday, August 5, 2010

Overwriting the Master Boot Record after installing windows

Overwriting the Master Boot Record

IconsPage/IconWarning3.png
Existing MBR will be lost. In order to dual-boot your computer, we will be creating a new Master Boot Record to include all operating systems, including Ubuntu Linux and Microsoft Windows. This is to be expected.
Your Ubuntu partition is now mounted. You will need to continue Using the Terminal.
Verify if your partition is correct.
mount | tail -1 
You should see output similar to this:
/dev/sda2 on /media/0d104aff-ec8c-44c8-b811-92b993823444 type ext4 (rw,nosuid,nodev,uhelper=devkit)
Note the designation for the disk /dev/sda which you will be using later, and the directory in /media.
IconsPage/IconHint2.png Use Tab Completion in Terminal to complete the path. Hitting the key will automatically finish file names, directory locations, and other long or hard to type file names.
To make sure this is indeed the Ubuntu boot partition, run ls /media/0d104aff-ec8c-44c8-b811-92b993823444/boot, substituting 0d104aff-ec8c-44c8-b811-92b993823444 with your volume's UUID from before, which should output something like this:
config-2.6.18-3-686      initrd.img-2.6.18-3-686.bak  System.map-2.6.18-3-686
grub                     lost+found                   vmlinuz-2.6.18-3-686
initrd.img-2.6.18-3-686  memtest86+.bin
If what you have is not similar, unmount it and try another partition.
Now that everything is mounted, we just need to reinstall GRUB by specifying the correct directory and the correct drive name:
sudo grub-install --root-directory=/media/0d104aff-ec8c-44c8-b811-92b993823444 /dev/sda
If you get BIOS warnings try:
sudo grub-install --root-directory=/media/0d104aff-ec8c-44c8-b811-92b993823444 /dev/sda --recheck
IconsPage/warning.png Replace /dev/sda with the location you want to install GRUB on.
If all went well, you should see something like this:
Installation finished. No error reported.
This is the contents of the device map /boot/grub/device.map.
Check if this is correct or not. If any of the lines is incorrect,
fix it and re-run the script `grub-install'.

(hd0)   /dev/sda
Reboot, making sure to boot to your hard drive and not to the live CD. Grub should be installed and both Ubuntu and Windows should have been automatically detected and listed in the menu.
The Master Boot Record will execute Grub as the initial bootloader. The Windows bootloader is contained within the Windows partition and will then be chainloaded by the Grub bootloader.

For Grub Legacy

Please refer to the guide
https://help.ubuntu.com/community/DualBoot/Grub#Ubuntu%209.10%20&%20earlier