Updated : Feb 06, 2010 in Linux

Recover Grub for Linux after Windows re-install

After I installed Linux Mint 8 with ext4 filesystem on /, I happned to have to reinstall Windows which whipped
out my grub Boot loader of Linux Mint 8 from MBR. So after I googled around I finally found a site that explains
how to recover a grub2 from an installed Linux. In my case Linux Mint 8 is using ext4 as root directory.
The following instructions were taken, and slightly modified to my situation, from:
http://www.ubuntu-inside.me/2009/06/howto-recover-grub2-after-windows.html
Many thanks to him. On some systems like Suse the mounting of /proc and /dev may not be needed,
but in my experience it is needed in many cases. Only a chroot to the target system is not enough.
That was the clue that was missing in my many attempts to recover grub in MBR.

This method worked with me on a MAC Book pro where I had ReFIT as boot manager,
MAC OS X, Windows XP, Linux Mint 8 and Ubuntu 9.10 all in the same box which used MBR only.

The main principles are the following:

– boot another Linux, using either a LIVE CD/USB or another means(it must be able to handle ext4 if the target system is ext4)
– mount the Linux root partition in question (the one that needs its grub to be recovered)
– do some preparations before chroot (mount the live /dev and /proc inside the chroot)
– chroot to the mounted system
– issue the grub-install /dev/sda
– unmount everything methodically
– reboot

Here are the details:
=============
# Boot a live system which can handle ext4 (if your Linux Mint is using ext4)
# Best is to boot the Linux Mint Original Install/Live CD/DVD
# Start a terminal

# Login as root
sudo su -

# make a list of partitions on the local hard disk
fdisk -l

This will show your partition table.Here is my table to understand it better :

/dev/sda1 29 8369 66999082+ 83 Linux
/dev/sda2 * 8370 13995 45190845 7 HPFS/NTFS
/dev/sda3 13996 14593 4803435 5 Extended
/dev/sda5 13996 14593 4803403+ 82 Linux swap / Solaris

# Assuming that we want to recover the grub of the Linux installed on /dev/sda1, here are the commands:
# Note: I’m using an extra subdirectory in /mnt instead of /mnt because many LIVE CD system are already using the /mnt.
# Mount the target system
mkdir /mnt/sda1
mount /dev/sda1 /mnt/sda1

# Prepare some needed components
mount --bind /dev /mnt/sda1/dev
mount --bind /proc /mnt/sda1/proc

# change environment to the target system
chroot /mnt/sda1

# re-Install grub in MBR
grub-install /dev/sda

# If you get some errors then you can run the following command
grub-install --recheck /dev/sda

Now you can exit the chroot, umount the system and reboot your box :

exit
umount /mnt/sda1/dev
umount /mnt/sda1/proc
umount /mnt/sda1
reboot

9 Comments

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: