So, I had Windows 7, Ubuntu happily coexisting with a Grub2 on MBR. I installed Windows 8 as a fresh installation after deleting the Windows 7 files (Program Files and Windows directory) to preserve my data, and as expected the Windows 8 Bootloader overwrote Grub2, leaving me with no option to Boot into Ubuntu.
The following is the procedure I followed to recover Grub:
Boot into a Live CD of Ubuntu.
Run a terminal as root and get the hang of the partitions:
[email protected]:~$ sudo su [email protected]:/home/ubuntu# fdisk -l Disk /dev/sda: 320.1 GB, 320072933376 bytes 255 heads, 63 sectors/track, 38913 cylinders, total 625142448 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk identifier: 0x00073736 Device Boot Start End Blocks Id System /dev/sda1 * 2048 186062847 93030400 7 HPFS/NTFS/exFAT /dev/sda2 186062848 248309759 31123456 7 HPFS/NTFS/exFAT /dev/sda3 248309760 268789759 10240000 83 Linux /dev/sda4 268789760 625141759 178176000 5 Extended /dev/sda5 549278478 592364744 21543133+ 83 Linux Partition 5 does not start on physical sector boundary. /dev/sda6 592375808 625141759 16382976 82 Linux swap / Solaris [email protected]:/home/ubuntu#
Now, we bind the device which contains the Linux partition Boot (typically the First Linux partition)-/dev/sda3 in my example.
mount /dev/sda3 /mnt mount --bind /dev /mnt/dev mount --bind /proc /mnt/proc cp /etc/resolv.conf /mnt/etc/resolv.conf chroot /mnt (This takes a few seconds) grub --install --recheck /dev/sda
Note that the last command reinstalls grub to a location. In my case, I wanted to install to MBR of my first hard disk, so I used /dev/sda (Not /dev/sda3)
This procedure replaces the Windows 8 bootloader from MBR, in addition it also checks all the installed OSes that it can find on your system and adds entries for these to the new grub configuration file.
The process is now over and you can reboot now!