2008-12-08

How to restore grub after Windows installation

There's nothing magical about it, you can easily Google it up, but I always forget the "find /boot/grub..." part and there are many other ways people explain this procedure, so I'm adding a screenshot as I'm doing it yet another time.

This is a best and easiest way to fix MBR after Windows f*ck it up.



In short:
1. boot from Ubuntu live CD (or any other live cd)
2. start a terminal
3.

sudo grub
find /boot/grub/stage1
root (hdX,Y)
setup (hdX)
quit


If you've got several drives you should check if your Windows partition is bootable and the other ones are not, otherwise if you install grub into linux partition, Windows will "fix" itself by changing bootable flag. To view and change bootable flags in Ubuntu Live go to System > Administration > Partition Editor (or run sudo gparted in terminal). The rest is illustrated below.






If grub loads but boot fails, it means grub detected your partitions incorrectly. Hit 'e' on linux entry, change the "root (hd1,0)" to "root (hd0,0)" or vice versa and press 'b' to attempt a modified boot. Repeat the "sudo grub" procedure when booted, but choose "setup (hdX)" target the oposite of your "root", i.e., if you did "root (hd1,0)", do "setup (hd0)" instead of "setup (hd1)". You should also edit /boot/grub/menu.lst afterwards and change all (hd0 to (hd1 and (hd1 to (hd0 to fix the boot menu.

Does all software have to suck?..

16 comments:

  1. Very helpful post. I installed Windows 7 RC1 in place of Windows 7 Beta on my triple boot (ubuntu, Vista (for work)) system and it killed GRUB. This helped me fix it quickly. I didn't have to manage flags or anything, either (because of previous setup?).

    Thanks loads!

    Nick C
    http://chapmanIT.com

    ReplyDelete
  2. Great post, thank you! Very clear instructions!

    ReplyDelete
  3. Helped me a lot. This is by far the best instructions ever. Other forums leave the manage flags part out!! Kudos!

    ReplyDelete
  4. This saved my ass. You are the man.

    ReplyDelete
  5. Hi
    I have tried that this is what I get:
    ubuntu@ubuntu:~$ sudo grub
    sudo: grub: command not found

    Thanks

    ReplyDelete
  6. Thank you. Well done and easy to follow.

    ReplyDelete
  7. thank you.. excellently done

    ReplyDelete
  8. Good post!

    If you installed Ubuntu on a different disk, you need to use setup (hd0) though, not the hd returned by the root command.

    ReplyDelete
  9. Thanks, it was very helpful for me.
    But a friend has the same problem but he don't has a cd reader. How can he fix his problem?

    ReplyDelete
    Replies

    1. > But a friend has the same problem but he don't has a
      > cd reader. How can he fix his problem?


      You can make an USB version of Ubuntu Live Cd by installing package usb-creator-gtk and using it to install a live cd image to an usb thumbdrive: https://help.ubuntu.com/community/Installation/FromUSBStick

      Delete
  10. Hi
    I have tried that this is what I get:
    ubuntu@ubuntu:~$ sudo grub
    sudo: grub: command not found

    I also get this error, it seems the grub is not installed, and the sudo /sbin/grub also doen not work. any tips?

    ReplyDelete
  11. Try finding your grub then:
    find / -name grub

    ReplyDelete
  12. You can install packages with the Live CD if needed bug Grub should be on eveyone's system. If you run gparted does it say your file systems are healthy? Can you mount them?

    If you have a SCSI controller do you need to use sda instead or is that just for linux itself?

    ReplyDelete
  13. ok I'm in grub but when I do step two (find /boot/grub/stage1) I get the following message "Error 15: File not found" Any ideas?

    ReplyDelete
  14. Hey all my friends you can find best solution of this problem over here:http://goo.gl/HXsZv

    ReplyDelete

Spam comments (i.e. ones that contain links to web development services) will be reported along with user profiles!

Note: only a member of this blog may post a comment.