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)
stigebil wrote:
This worked very well. Thank you for your help
Posted on 24-Sep-06 at 6:38 pm | Permalink
Davide wrote:
Thank you, after trying a dozen of how-to's yours has been the first to work.
Posted on 01-Nov-06 at 6:13 am | Permalink
Antipant wrote:
THANK YOU!!!!
This works like well oiled machine!
Thank you man!
Posted on 27-Nov-06 at 6:48 am | Permalink
tfager wrote:
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?
Posted on 06-Feb-07 at 3:08 pm | Permalink
Andrej wrote:
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.
Posted on 06-Feb-07 at 10:51 pm | Permalink
David Pinto wrote:
I LOVE YOU!!!
Posted on 15-Mar-07 at 3:41 am | Permalink
Jaime Bonilla wrote:
Thank you again great help!!
Posted on 22-Apr-07 at 12:26 am | Permalink
steve m wrote:
followed other how-to's without success, found yours and it worked a treat. many thanks, your article saved the day!
Posted on 28-Apr-07 at 12:21 pm | Permalink
lost_amigo wrote:
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
Posted on 21-Aug-07 at 3:16 am | Permalink
Andrej wrote:
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
Posted on 21-Aug-07 at 7:13 am | Permalink
rlouvot wrote:
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
Posted on 12-Dec-07 at 7:15 am | Permalink
Ozzy wrote:
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
Posted on 06-Jan-08 at 4:12 pm | Permalink