GRUB: Restore GRUB

Description
Booting with a Windows XP installations cd means that the bootsector gets overwritten and thus grub won't boot any longer. This article describes how to reinstall grub into the bootsector. Quick steps:

If you have a sepecial bootpartition you should also mount that one now. Use --no-floppy to skip probing for floppydrives. Alternative you could run grub-install here and skip the next step. grub> root (hd0,0) grub> setup (hd0) grub> quit root points to the drive and partition that contains the boot-directory and setup points to the drive that grub should be installed into.
 * 1) Boot with a livecd. Make sure to login as root. In this example I use the Gentoo 2005.1 livecd (universal installation cd).
 * 2) Mount appropriate partition
 * 3) mkdir /mnt/foo
 * 4) mount /dev/hda2 /mnt/foo
 * 1) mount /dev/hda1 /mnt/foo/boot
 * 2) chroot into the partition
 * 3) mount -t proc none /mnt/foo/proc
 * 4) chroot /mnt/foo /bin/bash
 * 5) run grub
 * 6) grub --no-floppy
 * 1) Install grub on the bootsector.
 * 1) exit out of the chrooted envirioment and reboot
 * 2) exit
 * 3) reboot

Summary
Boot with a livecd, login as root grub> root (hd0,0) grub> setup (hd0) grub> quit
 * 1) mkdir /mnt/foo
 * 2) mount /dev/hda2 /mnt/foo
 * 3) mount /dev/hda1 /mnt/foo/boot
 * 4) mount -t proc none /mnt/foo/proc
 * 5) chroot /mnt/foo /bin/bash
 * 6) grub-install
 * 1) exit
 * 2) reboot

How to find out which drive grub should use
Having problems with linux and grub reporting the drives in a different order?

Grub maintains a list of what a linux drive would be in grub. Look at /boot/grub/device.map once you booted the system. In case you need to know when you booted using the livecd, just look at the same directory but on the mounted partition.
 * 1) less /boot/grub/device.map (hd0) /dev/hda

As you can see the file first tells us the drive as grub reports it and then how linux would. Here the drives are listed in a correct order but using IDE-controller card etc can make the orders a bit confusing.

Where is my boot partition?

How do I know which partition holds my bootfiles? Grub has a simple command to find it. grub> find /boot/grub/stage1 (hd0,0)

If it won't return anything you might have a separate boot partition, so try this instead. grub> find /grub/stage1 (hd0,1)

Grub just looks at the partition and checks if it can find the file you asked for. It won't look recursive so we need to specify the full path. In case you have a separate boot partition we need to specify the full path but with /boot as base.