Thursday, November 18, 2010

How to restore dual boot after reinstalling Windows

I have been running a dual boot system at home with Windows XP and Ubuntu for quite some time. Recently, there was some problems with my Windows, and I have to reinstall the operating system as I was unable to find a solution. This in turn lead to other problems. I was unable to boot up to Ubuntu after reinstalling window. I have been using the grub loader that came with the Ubuntu installation to handle the dual boot. Previously, a grub menu will appear for selection of which operating system to boot up with. Now the grub menu no longer appears, with the system booting straight away to Windows. The Windows installation must have overwritten the Master Boot Record (MBR), which was kind of expected.

Anyway I tried to google search for a solution, and the following were the steps to resolve the problem that appear in the most of the forum postings or articles I have found:
  • sudo grub
  • find /boot/grub/stage1
  • root (hd0,1)
  • setup (hd0)
  • quit
Unfortunately, what has worked for others did not work for me. I have to research a bit more to find out what the above commands are for, and adjust accordingly based on my system.

Anyway my system consists of 2 harddrives, with Windows XP installed in the primary harddrive and Ubuntu in the secondary harddrive. The MBR is in the primary harddrive, while the grub program is in the secondary harddrive.

Following are the steps I have taken that have finally helped me solve the problem, as well as some explanation for each step:
  • Boot up using a ubuntu live CD.
  • Open a terminal and type: 
> sudo grub
  • In the grub command line utility that appears, type the following:
grub> find /boot/grub/stage1
  • The above command is for finding where your grub is located. In my case the value returned is: hd1,0. This means grub is in the 1st partition of my second harddrive. If your grub is in the 2nd partition of the first harddrive, the value returned should be hd0,1.
  •  The next command is to "tell" MBR where grub is located. So you should use the value found in the step above:
grub> root (hd1,0)
  • Make sure there is a space between "root" and the opening bracket.
  • Next step is to tell grub which MBR to fix. Typically, this should be the first harddrive, which means hd0 should be used. If you have only one harddrive then it should be hd0.
grub> setup (hd0)
  • After that you should see some statements about the program is running and whether it is successful.
  • Once the program has finished running, you can quit the utility:
grub> quit

Now another thing I have to mention is that my Ubuntu was a rather old version (version 8.10). It is still using the so called "legacy grub". I think for Ubuntu version 9.10 and after, grub program used is grub2. The above steps are meant for "legacy grub". If you are using grub2, please refer to my related links for the solution.

Related Links

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...