Restore Grub 2.0 after Windows 7 Install (Ubuntu 11.04, 10.10, 10.04 or 9.10)
I had Ubuntu 9.10 (this approach works for 10.04 Lucid and 10.10 Maverick, 11.04 Natty as well) already installed on a machine and wanted to dual boot it with Windows 7. Dual booting Ubuntu with Windows 7 already installed is easy, as described here. The reverse of it, i.e. creating dual boot Windows 7 with Ubuntu already installed is not that difficult either. You start by first resizing your Ubuntu partition, then create a Windows NTFS partition. You can do so using an Ubuntu Live CD or a Gparted Live CD. Then boot with Windows 7 DVD and install it. The problem is that the Grub would be gone and you won’t be able to boot into Ubuntu anymore.
This post discusses the easy way of restoring Grub2 using Ubuntu Live CD. First, boot with the Ubuntu Live CD. Now mount the partition, which has Ubuntu installed on it. If you had a separate partition for /boot, then you would have to mount that too. Mounting the partitions is super easy. Just go to Places in the top Gnome menu and try browsing to your corresponding partition by clicking on it. It would automatically get mounted and open in nautilus.
Now just run the following command to install Grub2 in the Master Boot Record (MBR) of your first booting hard drive.
sudo grub-setup -d /media/XXXXX/boot/grub -m /media/YYYYY/boot/grub/device.map /dev/sda
Where XXXXX represents the name or UUID of the partition that you have mounted. If your /boot partition is separate from your / partition then YYYYY above would be different from XXXXX, else both of them would be identical. The command above assumes that /dev/sda is your primary or first device in hard disk boot order. If not then replace it with /dev/sdb or sd_ fill the blank with appropriate letter.
If you don’t have a device.map file, you should try this way (thanks cibonato for pointing this out):
sudo grub-setup -d /media/XXXXX/boot/grub ‘(hdx)’
Where x is the letter corresponding to the hard drive number-1, for example if you want to install grub on first physical hard disk (we are not talking about partitions), then x = 0. For second drive it would be hd1.
After you have run the command, reboot and you should be able to boot in Ubuntu but not in Windows, to fix it run the following command in a terminal and Grub boot list would be updated to include Windows in it. Also if you want to change boot order read this.
Now reboot and you should have the choice to boot in both Windows and Ubuntu. For more information about Grub2 setup see this.
You might also like
|Install Gnome3 / Gnome Shell on ubuntu 11.04 (Natty)/Ubuntu 10.10 (Maverick) While Gnome3...||Install VirtualBox Guest Additions in Ubuntu 11.04 Natty Guest VirtualBox...||Ubuntu 11.04 Natty Narwhal (Alpha 1) Preview It is going...||Change Default Boot Order for Grub in Ubuntu 10.10 Maverick Meerkat Command-line...|