Skip to content

February 17, 2007

20

Restore Grub in Ubuntu after installing Windows

When you install some operating systems such as Windows or Mac OS X, they will overwrite your master boot record. If you have Linux installed you will be unable to access it, until you restore Grub on the MBR.

The easiest way is to find your Ubuntu or other Linux rescue/live/installation CD and boot it. Pop open a terminal and first find which partition is your root using fdisk.

$ sudo fdisk -l
Device Boot Start End Blocks Id System
/dev/hda1 * 1 2550 20482843+ af Unknown
/dev/hda2 2551 3825 10241437+ 83 Linux
/dev/hda3 3826 3890 522112+ 82 Linux swap / Solaris
/dev/hda4 3891 12161 66436807+ 7 HPFS/NTFS

Here we see that /dev/hda2 is our Linux partition, so we will want to mount it in order to read the Grub configuration.

sudo mount /dev/hda2 /mnt

If your don’t get any errors now your root partition should be mounted under /mnt. You can check for the grub configuration by listing the contents of the directory /mnt/boot/grub.

Now to restore the configuration just write the following.

$ sudo grub-install —-root-directory=/mnt /dev/hda

This will install Grub to MBR and use the configuration files in /mnt/boot/grub. Now just reboot your computer and you will hopefully be greeted with the ever friendly Grub menu once again.

Read more from Articles
20 Comments Post a comment
  1. Feb 28 2007

    Might want to note that its –root-directory not -root-directory

    Other than that this saved me lots of time

    Reply
  2. Feb 28 2007

    Man they blend together That is 2 -’s – -root-directory (w/o the space)

    Reply
  3. Feb 28 2007

    [quote comment="19934"]Might want to note that its –root-directory not -root-directory

    Other than that this saved me lots of time[/quote]
    Thanks for noticing. It seems like WordPress is suppressing one dash if there are two in a row. Maybe three in a row is the correct recipe.

    Edit: Four ones did it good enough. Thanks again.

    Reply
  4. Feb 28 2007

    I tried this just now and got:
    “/dev/hda does not have any corresponding BIOS drive.”

    Any ideas?

    Reply
  5. Feb 28 2007

    [quote comment="20040"]I tried this just now and got:
    “/dev/hda does not have any corresponding BIOS drive.”

    Any ideas?[/quote]
    Well, I was a bit unclear about that I realize. You have to install it on the device that is reported by fdisk -l. My best guess is that you should use /dev/sda instead.

    Reply
  6. Feb 28 2007

    I just got it working with

    sudo grub
    root (hd0,4)
    setup (hd0)

    - and am writing this from Ubuntu, after verifying XP still boots :-)

    (the disk is /dev/hda5)

    Reply
  7. Thankful guy
    Mar 3 2007

    Great guide, worked instantly in Xubuntu. Thanks

    Reply
  8. Mar 3 2007

    [quote comment="21009"]Great guide, worked instantly in Xubuntu. Thanks[/quote]
    Glad I could help!

    Reply
  9. Martin
    Oct 21 2007

    Tack sÃ¥ mycket. Räddade min kväll idag dÃ¥ ;) Hade dock en sata-disk sÃ¥ det var sda istället för hda … :)

    Reply
  10. Nov 11 2007

    [quote comment="46986"]Tack sÃ¥ mycket. Räddade min kväll idag dÃ¥ ;) Hade dock en sata-disk sÃ¥ det var sda istället för hda … :) [/quote]
    Kul att du hade nytta av den. Ja, alla har ju sata nuförtiden, så jag borde kanske byta i guiden.

    Reply
  11. Alan
    Jun 16 2008

    Great! it’s really i need

    Reply
  12. George
    Nov 27 2008

    Great guide guys, keep it up!!!!

    Thumbs up!!!!

    Reply
  13. Nov 30 2008

    @Alan @George
    Thanks!

    Reply
  14. Alther
    Jan 17 2009

    Thank you very much! Super Grub Disc don’t help, but with this advice i can manage my problem with grub.

    Reply
  15. Jul 4 2009

    thank you i alwase make install ubuntu in other partion 2 restore grub :)

    Reply
  16. Jul 5 2009

    thank you i alwase make install ubuntu in other partion 2 restore grub :)

    Reply
  17. isak
    Sep 1 2009

    tack som tusan, på ubuntuforums tar de lite omvägar ;)

    Reply

Trackbacks & Pingbacks

  1. Recuperar Linux após instalação de outro Sistema Operacional / RESTORING LINUX BOOT MANAGER « ¿ What if God smoked cannabis ?
  2. Não reinstale nada por causa do Grub « Pequeno diário de des-ilusões.

Share your thoughts, post a comment.

(required)
(required)

Note: HTML is allowed. Your email address will never be published.

Subscribe to comments