Sunday, June 8, 2008

Fixing the MBR

    This weekend I decided that I was going to load Fedora 9 onto my laptop and dual boot with Windows XP.  First of all I have a Toshiba Satellite A305-S6843 which is a great laptop and has never given me any problems.  I comes with an Intel T8100 (2.1 GHz), 4 GB RAM, 2x200 GB HD and an ATI Mobility Radeon HD 3470.  It originally came with Windows Vista but after only a month I was fed up with it and paid the $140 for the OEM Windows XP Pro x64.  I installed XP on the first 200GB HD leaving the second hard drive open.  So this weekend I decided that I would load Fedora 9 onto the second hard drive.
    After much frustration and searching (thats another story) I was able to get the live fedora 9 CD to boot and installed the OS that way.  Apparently I wasn't paying attention and told it to install grub on the boot sector for the second drive.  So when I restarted it booted directly into windows as if nothing had happened.  I was able to press F12 and use the BIOS's built-in boot manager to select the second hard drive and boot into linux that way.  For a while that was fine but then I decided that I would load grub into the MBR so that I could easily select which OS to boot.  I did it using the grub-install command
grub-install /dev/sda1
Oops!  I just overwrote the boot sector of the windows partition.  Consequently this also made it impossible to mount the ntfs partition or boot at all.  When trying to boot the MBR all that was displayed was 'GRUB'.
    At this point I was pretty sure that I had lost everything on the windows drive and would have to re-install Windows.  I just happened to stumble across a post by a guy who had a similar problem and he described how he fixed it using the Windows 98 SE boot disk.  This gave me the idea to use the Windows install CD and the recovery console.
Solution
Step 1:Insert the Windows XP install CD and restart the computer.
If your computer uses SATA with AHCI you will either need to set it to compatability mode in the BIOS or create a slipstream disk with the SATA drivers
Step 2:When the setup finishes loading drivers it will ask you if you want install the Windows XP operating system or if you want to use the Recovery console.  Press R to enter the recovery console.
Step 3:Use the fixmbr command to fix the master boot record.
fixmbr
Step 4:Use the fixboot command to fix the boot sector of the drive.
fixboot c:
Step 5:Exit the Recover console to restart the computer.
exit
If you set the SATA to compatability don't forget to set it back in the BIOS.
Step 6:Boot into Linux and bring up the terminal.  Run the grub console.
grub
Step 7:Set the root linux partition using the root command.  The root partition is set using the hard drive number.  For my system linux was installed on the second hard drive (hd1) and the first partition on that hard drive (0).
root (hd1,0)
You'll know you selected the correct partition when the grub console responds telling you it found the filesystem ext2fs.
Step 8:Tell grub to setup the MBR.
setup (hd0)
Step 9:The /etc/grub/grub.conf file will probably need to be edited to reflect the correct hard drives and paths.  I am not going to get into this here because there are plenty of tutorials on the internet about how to do this.
    That should allow you to use grub to boot into both Windows XP and Linux.

1 comment:

Fleck0411 said...

wow i am glad you are off breaking my laptop.