Nov 12, 2009
Recovering GRUB2 after hard-drive upgrade
Here’s how to do it:
Boot into Ubuntu Live CD.
Mount the root disk (Disk on which Ubuntu is installed).
mkdir /media/root
mount /dev/sda7 /media/root
where /dev/sda7 is your disk.
If you don’t know which disk the ubuntu is installed on, you can fdisk
sudo fdisk -l
Now, when you can install grub using grub-install
sudo grub-install --root-directory=/media/root /dev/sda --recheck
This will install the grub on the mounted disk. You can now reboot and get into your Ubuntu and upgrade it to GRUB2.
If this doesn’t work, you will have to change the root to the hard disk and install grub. To do that,
Unmount your boot partition (I’ll take sda7 as the example again) before proceding.
mkdir /mnt/root
mount /dev/sda7 /mnt/root
mount -o bind /proc /mnt/root/proc
mount -o bind /dev /mnt/root/dev
chroot /mnt/root
You may need to run these as root/superuser. If successful, you’ll get the terminal access to your boot partition. You can now install the grub using apt-get.
apt-get install grub
update-grub
But since, this is a new hard-drive, uuid won’t match. Hence, booting will fail.
To address this issue, you can install the grub2 without restarting
apt-get install grub2
grub-mkdevicemap
update-grub2
Reboot. Grub2 should be installed now.
