Overwriting the Windows bootloader
This will overwrite your Windows Boot Loader. It is OK to do this, in fact that is the goal of this how to (in order to boot Ubuntu)
Boot from a Live CD and open a terminal. You’ll need to run a few commands as root so you can use sudo -i to get a root shell and run them normally instead of using sudo on each of them. Be extra careful when running a root shell, especially for typos!
We’ll need to find which partition your Ubuntu system is installed on. Type the command fdisk -l. It will output a list of all your partitions, for example :
fdisk -l
Disk /dev/hda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 1 8 64228+ 83 Linux
/dev/sda2 9 1224 9767520 83 Linux
/dev/sda3 * 1225 2440 9767520 a5 FreeBSD
/dev/sda4 2441 14593 97618972+ 5 Extended
/dev/sda5 14532 14593 498015 82 Linux swap / Solaris
/dev/sda6 2441 14530 97112862 83 Linux
Partition table entries are not in disk order
Here I have three Linux partitions. /dev/sda2 is my root partition, /dev/sda1 is my /boot partition and /dev/sda6 is my /home partitions. If you only have one, obviously this is the one your Ubuntu system is installed on. If you have more than one and you don’t know which one your Ubuntu is installed on, we’ll look for it later. First, create a mountpoint for your partition, for example :
mkdir /media/root
Then mount your partition in it. If you don’t know which one it is, then mount any of them, we’ll see if it’s the correct one.
mount /dev/sda2 /media/root
Of course, replace /dev/sda2 with the correct name of your partition. You can check if it’s the correct one by running ls /media/root, which should output something like this :
bin dev home lib mnt root srv usr
boot etc initrd lib64 opt sbin sys var
cdrom initrd.img media proc selinux tmp vmlinuz
If what you have looks not at all like this, you didn’t mount the correct partition. Do umount /media/root to unmount it and try another one. You also need to mount your /boot partition if you made one, like this :
mount /dev/sda1 /media/root/boot
To make sure it was the correct one, run ls /media/root/boot, 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
Once again, if what you have doesn’t fit, unmount it and try another partition.
Now that everything is mounted, we just need to reinstall GRUB :
sudo grub-install --root-directory=/media/root /dev/sda
If you got BIOS warnings try:
sudo grub-install --root-directory=/media/root /dev/sda --recheck
Of course, 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 (to your hard drive). Grub should be installed and both Ubuntu and Windows should have been automatically detected.
If, after installing grub, Windows does not appear in the boot menu you will need to edit /boot/grub/menu.lst (That is a small “L” and not the number 1 in menu.lst)
Open a terminal and enter :
gksu gedit /boot/grub/menu.lst
Or, in Kubuntu:
kdesu kate /boot/grub/menu.lst
Your Windows stanza should look something like this :
title Windows XP/Vista # You can use any title you wish, this will appear on your grub boot menu
rootnoverify (hd0,0) # This is the location of the windows partition
makeactive
chainloader +1
Note: Put your Windows stanza before or after AUTOMAGIC KERNEL LIST in the menu.lst
Preserving Windows Bootloader
This method allows you to restore GRUB and keep the Windows bootloader as your primary bootloader. Thanks to Ubuntu’s support for NTFS writing it’s now an absolute cinch.
The method shown above puts GRUB back on the MBR (master boot record) of the hard drive instead of in the root partition. But you probably won’t want that, if you use a third-party boot manager like Boot Magic or System Commander. (The original poster also suggested that this would be useful to restore the Grub menu after a re-ghosting.) In that case, use this alternative.
If you have your Linux system in a second (or third…) hard disk this method will not work. Please check Super Grub Disk’s method that address this problem.
Restoring GRUB
1. Boot from a Live CD, like Ubuntu Live, Knoppix, Mepis, or similar. Ideally use Ubuntu 8.04 or higher as this has NTFS write support and makes life a bit easier; this isn’t necessary, just handy.
2. Open a Terminal. Open a root terminal (that is, type “su” in a non-Ubuntu distro, or “sudo -i” in Ubuntu). Enter root passwords as necessary.
3. Type “grub” which makes a GRUB prompt appear.
4. Type “find /boot/grub/stage1″. You’ll get a response like “(hd0)” or in my case “(hd0,3)”. Use whatever your computer spits out for the following lines. Note that you should have mounted the partition which has your Linux system before typing this command. (e.g. In Knoppix Live CD partitions are shown on the desktop but they’re not mounted until you double-click on them or mount them manually)
5. Type “root (hd0,3)” note the space between root and (hd0,3).
6. Type “setup (hd0,3)”. This is key. Other instructions say to use “(hd0)”, and that’s fine if you want to write GRUB to the MBR. If you want to write it to your linux root partition, then you want the number after the comma, such as “(hd0,3)”.
7. Type “quit”.
8. At this stage you can either restart the system and install your own bootloader, or you can continue and tell the Windows bootloader where to find GRUB which will handle booting Linux.
Making Windows Load GRUB (and then Linux)
This is taken from Dual-Boot Linux and Windows 2000/Windows XP with GRUB HOWTO which has been helping people dual boot since 2005, or maybe before.
1. In Linux open a command window.
2. Mount a drive which you can share with Windows; this could be a USB drive, a FAT32 partition on your machine, or if you are using a Linux distro which supports NTFS writing like Ubuntu 8.04+ (maybe earlier?) then you can mount the actual Windows c:\ drive itself! The big bonus of writing to the windows drive is that you are going to need to put a file there, so it saves copying a file around. For example
#mkdir /tmp/windows
#mount /dev/sda1 /tmp/windows
3. Now you are going to make a copy of your boot partition; finding what this is called is not 100% deterministic because Linux might call your drives sdX or hdX, whereas GRUB always calls them hdX and Linux names them [hd|sd][Letter][Number] whereas GRUB names them as hd[Number][Number]; note that df won’t work as you are booted from a live CD. But let’s have a go; if you installed GRUB on (hd0,0), then /boot is on hda1 or sda1, (hd1,0) == hdb1 or sdb1, (hd0,1) == hda2 or sda2, etc… this narrows you down to two possibilities, now issuing ls /dev |grep hd will let you know if you have that drive on your machine, if nothing comes up which matches, then you must have an sd drive. OK, great…
4. Having hopefully determined your boot partition issue the command (as root)
#dd if=/dev/sda2 of=/tmp/windows/linux.bin bs=512 count=1
Where /dev/sda2 is your boot partition and /tmp/windows/ is the drive you want to copy the boot sector image to.
5. If you haven’t created linux.bin in the Windows drive then you need to copy it there now.
6. Reboot into Windows, open c:\boot.ini in notepad, and on a new line at the bottom, add c:\linux.bin="Linux". This file might be write protected, if it is enable write in the right click context menu -> properties; you should disable write afterwards. Make sure that at the top of the boot.ini file there is a timeout set, i.e timeout=5. (Ah ha, you say, now I have NTFS support, why don’t I just edit boot.ini in Linux, the answer to this is that Linux and Windows represent line breaks in different ways, so even though you can edit the file, it won’t add a new line 残念)
7. That’s it, reboot and you will be given the option of booting into Linux, selecting that will chainload GRUB and this will let you boot into your Linux distro.
From: http://ubuntuforums.org/showpost.php?p=121355&postcount=5