Monday, March 15, 2010

Restoring Grub after Reinstalling Windows

Okay, you've had a very nice dual boot system with windows and linux set up, and you had to reinstall windows due to some some virus/upgrade/other issue. Boom! the first thing you see (or rather don't :P) after you restart is the windows boot loader which does not seem to be generous enough to show the ubuntu OS. This is in contrast to the Ubuntu boot loader (GRUB) which accommodates for other installed operating systems too. (For this reason, if you are setting up/reinstalling the whole system, it is generally advisable to first install windows, and then install Ubuntu.. This way, the windows boot loader will get replaced by GRUB which will allow you to boot into both the OSs).
Anyways, coming to our original issue, you have messed up with your boot loaders and now want to be able to boot into both the OSs.. do this:
1. Insert the Ubuntu Live CD and boot into it.
2. Once the CD gets booted, go to the live session and open a terminal.
3. Type 'sudo grub'. You will see a grub prompt like:
grub>
After this, type the following commands:
4. grub> find /boot/grub/stage1
- This will give you something like '(hdx,y)'
6. grub> root (hdx,y)
7. grub> setup (hdx)
8. grub> quit

Now, reboot the system, don't forget to remove the LiveCD and you should see your rocking dual boot system back!

References: check this.

5 comments:

Sue said...

cool!

The inner voice said...

very useful info. thanks :)

Prashanth Kamle said...

Does this work with grub 2.0 as well?

Dhaval said...

haven't tried that in grub2.. but I think it should work.. those are like basic grub commands...

Dhaval said...

Turns out it doesn't work in grub 2, and you have to do grub-install: http://www.ubuntugeek.com/how-to-restore-grub-boot-loader-after-installing-windows.html