Page 1 of 3 123 LastLast
Results 1 to 10 of 44

Thread: HOWTO: Restore GRUB (if your MBR is messed up)

Hybrid View

  1. #1
    arnieboy Guest

    HOWTO: Restore GRUB (if your MBR is messed up)

    Written by vnbuddy2002

    Restoring GRUB is quite simple in Ubuntu. Instead of going through all the "gain root access" and playing with shell commands, you can use the Ubuntu installation CD to restore it without going through all kinds of hassles.

    Here are the steps:

    1. Boot your computer up with Ubuntu CD
    2. Go through all the process until you reach "[!!!] Disk Partition"
    3. Select Manual Partition
    4. Mount your appropriate linux partions

    /
    /boot
    swap
    .....

    5. DO NOT FORMAT THEM.
    6. Finish the manual partition
    7. Say "Yes" when it asks you to save the changes
    8. It will give you errors saying that "the system couldn't install ....." after that
    9. Ignore them, keep select "continue" until you get back to the Ubuntu installation menu
    10. Jump to "Install Grub ...."
    11. Once it is finished, just restart your computer

    Good luck!.
    Last edited by arnieboy; June 5th, 2006 at 11:18 PM.

  2. #2
    Join Date
    Aug 2005
    Beans
    211

    Re: HOWTO: Restore GRUB (if your MBR is messed up)

    Just an alternative: you can put Grub on floppy.

    I used the method above when something went wrong during my first install (hoary hedgehog). This made me very careful, so at point 10 I choose to put Grub on floppy.

    Edit: I tried this in Breezy and it didnt work for me (dont know why, it could be me, the hardware, or even breezy). This method did work in Breezy:

    Boot from install CD, at the boot promt type: rescue
    Follow some simple instructions (such as type the host name of your computer) and you wil get a menu where you can choose to a partition to mount.

    The root partition of ubuntu is the first partition on my second hard disk, so I choose /dev/discs/disc1/part1.

    At the prompt (sh-3.00#) I typed: ls
    This produced a list of directories, such as boot, that convinced me that I mounted the right partition.

    Mount the floppy disk: mount /dev/fd0
    Install Grub on the floppy disk: sudo grub-install "(fd0)"
    including the qoute signs.

    Note: you can also chose the appropiate partition of your hard disk in case you want to restore your mbr.

    The response was:
    contents device map /bot/grub/device.map
    (fd0) /dev/fd0
    (hd0) /dev/sda
    (hd1) /dev/sdb
    asking if this was correct.
    I typed exit at the prompt because this was correct: ubuntu is on the 2nd sata disk (/dev/sdb).

    In the BIOS I put floppy as first boot device and could boot from foppy again.

    Note: if you need to edit device.map you need a different tutorial. My floppy was already formatted.

    This tutorial looks solid:
    http://www.yolinux.com/TUTORIALS/Lin...sk.html#RESCUE

    I still am booting from floppy because, if necessary, I can reinstall windows and it wont overwrite grub.

    This setup survived a dist-upgrade from hoary to Breezy; the entries for Breezy were added to the floppy automatically.

    I have two hard disks, one for windows and one for Ubuntu, but this should work with one hard disk as well. I suppose you can also use a bootable memory stick.

    Windows wants to be one the first partition on the first hard disk. I did not have to edit grub with the map option to make the windows think it is on the first disk. Windows is on the first hard disk because that is the sequence set in the BIOS. (When you boot from floppy it must be first in the BIOS boot sequence.)

    Note that this setup is not necessary for security, I just find it convienient.
    Last edited by yesplease; October 20th, 2005 at 05:37 PM.

  3. #3
    Join Date
    Aug 2005
    Beans
    428
    Distro
    Hardy Heron (Ubuntu Development)

    Re: HOWTO: Restore GRUB (if your MBR is messed up)

    Would you explain how to put grub on a floppy?

  4. #4
    Join Date
    Aug 2005
    Beans
    211

    Re: HOWTO: Restore GRUB (if your MBR is messed up)

    Quote Originally Posted by cbudden
    Would you explain how to put grub on a floppy?
    I edited the 2nd post in this tread to include this.
    Last edited by yesplease; October 19th, 2005 at 10:25 PM.

  5. #5
    Join Date
    May 2005
    Location
    Va, USA
    Beans
    428

    Re: HOWTO: Restore GRUB (if your MBR is messed up)

    After reinstallign Windows, GRUB is gone. I tried following your instructions, but I cannot get past step 4. How do you mount the partitions? If I go to the Install Grub part of the menu, it just puts me back to the partition manager, and if I hit enter, save changes after selecting my ubuntu partition, it says that it can't find root file system and won't let me continue. How do I put GRUB back?

  6. #6
    arnieboy Guest

    Re: HOWTO: Restore GRUB (if your MBR is messed up)

    Quote Originally Posted by Curlydave
    After reinstallign Windows, GRUB is gone. I tried following your instructions, but I cannot get past step 4. How do you mount the partitions? If I go to the Install Grub part of the menu, it just puts me back to the partition manager, and if I hit enter, save changes after selecting my ubuntu partition, it says that it can't find root file system and won't let me continue. How do I put GRUB back?
    u have to set your ubuntu partition as "/" (or the root partition ---> please dont confuse this with /root which is the directory for the root user)

  7. #7
    Join Date
    Sep 2005
    Beans
    9
    Distro
    Ubuntu Breezy 5.10

    Talking Re: HOWTO: Restore GRUB (if your MBR is messed up)

    Quote Originally Posted by arnieboy
    Written by vnbuddy2002

    Restore GRUB quite simple in Ubuntu, instead going through all the "gain root access" and play with shell commands, you can use the Ubuntu installation CD to restore it without going through all kinds of hassles.

    Here are the steps:

    1. Boot your computer up with Ubunto CD
    2. Go through all the process until you reech "[!!!] Disk Partition"
    3. Select Manual Partition
    4. Mount your appropriate linux partions

    /
    /boot
    swap
    .....

    5. DO NOT FORMAT THEM.
    6. Finish the manual partition
    7. Say "Yes" when it asks you to save the changes
    8. It will give you errors saying that "the system couldn't install ....." after that
    9. Ignore them, keep select "continue" until you get back to the Ubuntu installation menu
    10. Jump to "Install Grub ...."
    11. Once it is finished, just restart your computer

    Good luck!.

    This works perfect!!!!!! Thank you so much!!!!!

  8. #8
    Join Date
    Nov 2005
    Location
    Pune, India
    Beans
    838
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: HOWTO: Restore GRUB (if your MBR is messed up)

    Hi all,
    I didn't have the luxury of this guide hence had to do the old way. It's interesting & one can learn a lot in the old way.
    1. The first step is making sure that the computer can boot up through a CD. So while booting up either use Escape or Alt+F2 or whatever key combination is given to access the BIOS. There look an entry which says which device to boot first, make sure that it's on CD rather than hard disk or IDE0 etc.

    2. After making sure that the computer is able to boot off CD. Put in the Live CD & let it boot completely. Completely meaning till the desktop comes. If your computer is slow or has less RAM it will take quite some time. My 1.8 ghz + 128 DDRAM took around 30 minutes to fully come up. Your mileage may vary.

    3. Now press ALT+CTRL+F2 to get shell prompt. The shell prompt will be something like :-
    Code:
    ubuntu@ubuntu$ :-
    If u've got till here that means that u've a bash shell. If however u've got an unfamiliar shell then most probably its the c shell with csh or something like that. This has a limited set of commands that u can use & useless for our purposes. At any point one can use ALT+CTRL+F7 to acess the graphical boot-up.

    4. Moving to the next step get the partition tables for the devices using fdisk command:
    fdisk -l This will give a partition table of all the different partitions/hard disk fdisk can access. Here's a listing of what it can look like depending on u'r windows partition.

    Code:
    fdisk -l
    
    Disk /dev/hda: 80.0 GB, 80060424192 bytes
    255 heads, 63 sectors/track, 9733 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/hda1   *           1         511     4104576    b  W95 FAT32
    /dev/hda2             512        7651    57352050    f  W95 Ext'd (LBA)
    /dev/hda3            7652        9629    15888285   83  Linux
    /dev/hda4            9630        9733      835380   82  Linux swap / Solaris
    /dev/hda5             512        1531     8193118+   b  W95 FAT32
    /dev/hda6            1532        2551     8193118+   b  W95 FAT32
    /dev/hda7            2552        3571     8193118+   b  W95 FAT32
    /dev/hda8            3572        4591     8193118+   b  W95 FAT32
    /dev/hda9            4592        5611     8193118+   b  W95 FAT32
    /dev/hda10           5612        6631     8193118+   b  W95 FAT32
    /dev/hda11           6632        7651     8193118+   b  W95 FAT32
    The listing will differ in number of ways depending on whether the hard disk is a master or slave or it SATA or SCSI(sdx) or any no. of permutations & combinations.Look for
    Code:
    man fdisk
    as well as
    Code:
    info fdisk
    for complete documentation.

    Anyway, What we're looking for is the Linux partition. Here it's an single ext3 code 83 partition. So it's much simpler.

    5. Once you identified your device file mount it. :
    Code:
    mkdir /santana
    - the name can be anything.
    Code:
    mount /dev/hda3 /santana
    - What gave it away atleast in my system was that's its the only ext3 partition.

    6. Then use chroot command to start interactive shell with special root directory i.e. /santana will act as that special root directory.
    Code:
    cd /santana
    7.Use grub-install command to reinstall grub:
    Code:
     grub-install /dev/hda
    - this is for single hard disk in primary master configuration.

    8.Type exit and reboot the system. You should see your GRUB and Linux again.
    Last edited by ShirishAg75; December 26th, 2005 at 09:14 PM.
    Registered Linux user #468829

    http://flossexperiences.wordpress.com

  9. #9
    Join Date
    Oct 2005
    Beans
    18

    Re: HOWTO: Restore GRUB (if your MBR is messed up)

    Any idea how to adapt this to work if you had installed using LVM. None of this seems to be working for me unfortunately... The installer does not seem to recognize the install and keeps kicking me back to the partition screen. I tried playing around a bit more but I think I ended up blowing away the install. I've had this happen a couple times now that I've accidentally blown away grub and had to start from scratch because of using LVM .

    The only way I've found to partially recover when using LVM so far is to boot from the live CD, install EVMS-GUI, mount the LVM volume, copy the user data to another disk/partition, then completely reinstall Ubuntu and restore the data. Yuck....

    I feel I must be missing something simple... Any ideas?

  10. #10
    Join Date
    Oct 2005
    Location
    Trondheim, Norway
    Beans
    204
    Distro
    Ubuntu 7.04 Feisty Fawn

    Re: HOWTO: Restore GRUB (if your MBR is messed up)

    Arnieboy, I agree with Curlydave's post, point #4 needs more explaination.

    Also, you're referring to "the Ubuntu CD". Since most people here have two of them lying around, you should mention that this is the Ubuntu Install CD.

    And finally, before your step #8, I got an "Not installing to unclean target" error, which I also had to skip using "Continue". Don't know if this is common, but it might be worth mentioning.

    For the rest, a good guide. This is also the way I restored my GRUB after messing with the partition tables...

Page 1 of 3 123 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •