GRUB Recovery Using Fedora 10's LiveCD

If you are like me, chances are that you could not resist the urge to download and install Microsoft's public beta of the upcoming Windows 7 release.

So, I did install it at the expense of having my Fedora 10 GRUB overwritten by Windows 7's installer. Although W7 works fine now, I lost the ability to boot into FC10.

I booted the laptop using my FC 10 LiveCD and tried to do the mount root / chroot / grub-install routine that is described everywhere in the Internet, but I found that the chrooted system has no devices under /dev and this makes grub-install fail.

I went in circles for about half an hour until I came up with a solution: Use mount's "--bind" option to remount the LiveCD's /dev under the chrooted system's /dev.

So the whole procedure goes like this:

  • Boot and log into your FC10 LiveCD
  • Open a terminal and "su -" into the root account
  • Mount the root filesystem, mine was /dev/sda6 under /mnt/root (or whatever you like)
    • mount /dev/sda6 /mnt/root
  • Mount /proc
    • mount -t proc proc /mnt/root/proc
  • Copy /proc/mounts to mtab
    • cat /proc/mounts > /mnt/root/etc/mtab
  • Bind /dev to /mnt/root/dev (this makes devices visible to grub in chrooted environment)
    • mount --bind /dev /mnt/root/dev
  • Chroot
    • chroot /mnt/root /bin/bash
    • source /etc/profile
  • Re-install GRUB
    • grub-install --recheck "(hd0)"

And voilá! Happy booting!