Index of /andrejciho/Linux/Repairing Grub (distro independent)

Name Last modified Comments Description

Back Parent Directory

Repairing Grub (distro independent)

More often than not, whenever I installed grub into my MBR, it got corrupted. Sometimes after 1st reboot, sometimes after 10th. Either way, I stopped putting it there and have written about how to put it elsewhere in a previous post. Here I offer simple instructions how to repair/reinstall grub when it gets corrupted (wherever it's installed). It should work in any distro.

1. Boot from a linux liveCD, such as Knoppix or Gentoo minimal install CD.

2. Mount your file system (you can substitute "mylinux" for whatever you want, just stay consistent)
mkdir /mnt/mylinux
mount /dev/hda5 /mnt/mylinux

If you have your file system spread out across more partitions, mount it all inside the /mnt/mylinux. For example:
mount /dev/hda3 /mnt/mylinux/boot
3. Mount the /dev and /proc. These are dynamically generated by your liveCD and need to be present in your file system in a second - so don't skip this step.
mount -t proc none /mnt/mylinux/proc
mount -o bind /dev /mnt/mylinux/dev

4. Chroot to your file system
chroot /mnt/mylinux /bin/bash
5. Generate /etc/mtab (dynamically generated list of mounted file systems)
grep -v rootfs /proc/mounts > /etc/mtab
6. Reinstall grub to your boot partition
grub-install /dev/hda3
or to your MBR but I don't recommend it:
grub-install /dev/hda
or manually…
grub
NOTE: If you're using Windows' boot.ini to load your linux, you're going to have to re-dd your 512-byte bootsector file (see my previous post if you need instructions)

Comments (12) to “Repairing Grub (distro independent)”

  1. This worked very well. Thank you for your help

  2. Thank you, after trying a dozen of how-to's yours has been the first to work.

  3. THANK YOU!!!!

    This works like well oiled machine!

    Thank you man!

  4. Very insightful and useful article indeed, pretty much saved my day!
    A couple of comments though:
    1) Is there a smarter way to create /etc/mtab? My live CD (Kubuntu) mounted all kinds of stuff to directories that didn't exist on the chroot'ed disk, which confused grub-install. Editing mtab by hand saved the day though.

    2) Why would you not recommend installing GRUB on MBR?

  5. Thanks!
    I can imagine how Kubuntu flooded /etc/mtab. You are right, I could have spent more time describing how mtab works - maybe I'll do that one of these days. I always just used grub instead of grub-install. Thanks for your comment.

  6. I LOVE YOU!!!

  7. Thank you again great help!!

  8. followed other how-to's without success, found yours and it worked a treat. many thanks, your article saved the day!

  9. Hi, I am wondering…
    I am running a raid5 system with an AMD64 setup. I was reading your interesting article about rebuilding GRUB. I have a GRUB error 2 and it locks up after or during the setting up of Stage 1.5
    What I am wondering about is, in step 2 of your article you specify: If you have your file system spread out across more partitions, mount it all inside the /mnt/mylinux. For example:
    mount /dev/hda3 /mnt/mylinux/boot
    Does the fact that I am running Raid5 mean that I have to use this command for each drive in the array? ie: hdaa hda1 hda2 hda3 hda4 hdac
    Thank you in advance for your answer,

    lost_amigo

  10. lost_amigo.

    I wish I had raid5 but I unfortunately don't, so I don't have
    experience with this. However, I found a link that appears to have
    some info (in case you haven't already visited that website):
    http://gentoo-wiki.com/HOWTO_Gentoo_Install_on_Software_RAID#Installing_Grub_onto_both_MBRs

    I hope that helps.

    Andrej

  11. the only missing element is the –recheck option for grub-install if there's the error :
    /dev/hdX does not have any corresponding BIOS drive

    but thanks a lot

  12. Cheers mate

    Updated XP to Vista on my wifes Dual boot pc and of course overwrote the MBR.

    This worked flawlessly to fix it.

    Regards


Leave a Comment
*Required
*Required (Never published)
 

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-Spam Image