Wednesday, November 5, 2008

Restoring GRUB after reinstalling XP

For me, a common system setup is dual-boot Windows and Linux, and a common problem is an overwritten MBR (Master Boot Record) after reinstalling Windows XP, making it impossible to boot to Linux. Most sites recommend using a Linux install or rescue CD to fix this, but I prefer to install the GRUB bootloader on the Windows partition, and then use GRUB to boot into Linux to repair the boot record:
  1. Download the latest zip file from GRUB for DOS and extract the file grldr to C:\
  2. Run cmd and type:
    cd \
    attrib +r +s +h boot.ini
    edit boot.ini

  3. Append the line
    c:\grldr="GRUB"
    to the operating systems section, which is usually last. Save and quit.
  4. Type
    attrib -r -s -h boot.ini
  5. Reboot and select GRUB from the boot menu.
  6. From the grub prompt we can repair the system:
    find /boot/grub/stage1
    root (hdX, Y)
    setup (hd0)
    reboot

Take care with boot.ini as invalidating this file can render the system unbootable. In this case you must boot by another method, e.g. network, USB, CD or floppy.

No comments: