How to Restore GRUB and/or the MBR (Master Boot Record) under Fedora linux

by Marion Bates <mbates at>

Warning: filemtime(): stat failed for /var/websites/ in /home/mbates/ on line 56
Last modified: December 31 1969 16:00:00

Scenario: After installing a kernel upgrade via yum, rebooting the server resulted in a blank screen with blinking cursor in the upper-left corner, right after BIOS. No grub menu or anything else. Turns out that what had happened was, the MBR got corrupted or erased. We're not sure if it was caused by the kernel upgrade or if that was a coincidence. Anyway, using another howto as a framework, we did the following.

  1. Boot from CD and mount the system. We used the install disc because I never bothered to burn a rescue CD, har har. When you get to the splash screen, type "linux rescue" and hit return. It will ask you a couple things about your language and keyboard, and will offer to bring up the network interfaces -- I said no. Then it gave me the option to let it try to detect and mount the system read-writable, or read-only, or no auto-detect. I chose the first option and it worked.

  2. Fiddle with grub.conf, if necessary. Open /mnt/sysimage/boot/grub/grub.conf in an editor and check to make sure it looks okay. If you want to revert to a previous kernel option, you can add its parameters here, or they may already be in the list -- newest kernel info gets appended to the top. You can also change the default option (what gets highlighted in the grub menu) by changing the "default=0" line to something else; the first block is 0, second is 1, etc.

    If your grub.conf is missing or corrupted, you're kind of on your own. Here's a sample:

    title Red Hat Linux (2.4.18-14)
            root (hd0,1)
            kernel /boot/vmlinuz-2.4.18-14 ro root=LABEL=/ hdc=ide-scsi
            initrd /boot/initrd-2.4.18-14.img
    title Red Hat Linux (2.4.18-openmosix3)
            root (hd0,1)
            kernel /boot/vmlinuz-2.4.18-openmosix3 ro root=/dev/hda2 hdc=ide-scsi
            initrd /boot/initrd-2.4.18-openmosix3.img
    title WindowsME
            rootnoverify (hd0,0)
            chainloader +1

  3. Write to the MBR. Assuming grub.conf is intact, continue with the process. Type "grub" (return) to enter the grub shell.

    Tell grub where to find the requisite files. If you know where they are, enter something like:

    root (hd0,1)

    (hd0,1) means primary controller master, second partition. If you DON'T know where they are, type:

    find /boot/grub/stage1
    and then enter the root command with the correct parameters. Note: If you are using a separate /boot partition , as the official documentation says: "... if you have the partition /boot and you install GRUB images into the directory /boot/grub, GRUB recognizes that the images lies under the directory /grub but not /boot/grub.' Thus, if 'find /boot/grub/stage1' does not find the file, try 'find /grub/stage1'."

    Next, type:

    setup (hd0)
    This command will install grub on the MBR of the first drive.

  4. Test. Type quit and reboot. Everything should proceed normally.

    In our case, the details were all identical except that we used (hd0,0) in place of (hd0,1) because our /boot was on the first partition of the first drive.

    Get Euro-style oval stickers for Geeks!

    NEW -- the "magic/more magic" light switch cover!
    Click here for the story.