This method allows you to restore GRUB and keep the Windows bootloader as your primary bootloader. Thanks to Ubuntu's support for NTFS writing this method is now quite simple.
The previous method puts GRUB back on the MBR (Master Boot Record) of the hard drive instead of in the root partition. Should you not wish to do so, for instance if you use a third-party boot manager like Boot Magic or System Commander, this next suggestion will be helpful. Another reason to prefer this method is for when restoring the Grub menu after a re-ghosting. In either case, use this alternative.
Restoring GRUB
1. Boot from a Live CD, like Ubuntu Desktop, or similar. It is recommended to use Ubuntu 9.04 or newer as this has NTFS write support.
2. Open a Terminal. Open a root terminal (For non-Ubuntu live CDs type su the terminal. For Ubuntu based distros run sudo -i) 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 the output from this command for the following commands.
Note:
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) into the prompt. 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 at least 2005.
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 hard drive, or if you are using a Linux distribution which supports NTFS writing natively (Such as Ubuntu 8.04 or later) then you can mount the actual Windows C:\ drive itself! The advantage of writing to the Windows drive is that you are going to need to put a file there eventually, so it saves time copying a file around. For example:
#mkdir /tmp/windows
#mount /dev/sda1 /tmp/windows
However, when writing directly to the C:\ drive you could also do some damage to the system if you delete or move something. If you do pick the option to write directly, go in, put the file where it belongs, and touch NOTHING else.
3. Now you are going to make a copy of your boot partition. Finding out what this is called is not always completely reliable since the Linux naming conventions differ from the GRUB naming conventions. Linux labels partitions as hd[Letter][Number] or sd[Letter][Number] whereas GRUB always names them as hd[Number][Number]. If you installed GRUB on (hd0,0), then the /boot partition will be on hda1 or sda1. (Since (hd1,0) == hdb1 or sdb1, then by extension if you installed GRUB on (hd0,1) then the /boot partition will be on hda2 or sda2 and so on and so forth.) This narrows you down to two possibilities. If you now paste ls /dev |grep hd it will let you know if you have that drive on your machine. If nothing comes up which matches, then that means you must have an sd drive.
Note: The command df won't work as you are booted from a Live CD.
4. Having determined your boot partition run this command as root:
#dd if=/dev/sda2 of=/tmp/windows/linux.bin bs=512 count=1
Looking at this example /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. Next, reboot your computer and boot into Windows. Open c:\boot.ini in Notepad, and add a new line at the bottom:
c:\linux.bin="Linux"
This file might be write protected. If that is so, you need to enable writing to the file. To do so, right click, and from the context menu select Properties. Then uncheck the box that says "File is read only". Make sure to put that checkmark back afterwards.
Next, make sure that at the top of the boot.ini file there is a timeout set, i.e timeout=5 or some such number.
Do not edit this file from the Live CD, even if you have NTFS write support. 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.