Sunday, January 23, 2011

Recover Grub2 after Windows Installation, all Ubuntus

Grub is the default boot loader of Ubuntu. Upon powering on or restarting your computer, it lets you choose between the various operating systems installed, including Ubuntu, and loads them once you've made your choice. If you install Windows after the installation of Ubuntu, the Windows boot loader takes control of your disk's MBR and replaces Grub, thus leaving you only able to boot into Windows. In this case, in order to re-enable multi boot, you need to reinstall Grub2. This may also be needed after the installation of some other Linux distribution which comes with Grub Legacy, or of course, if you somehow manage to break Grub.

Boot an Ubuntu Desktop Live CD/USB (for instructions on how to create an Ubuntu Live USB, please see this post) and choose the "Try" mode. Once on the desktop, go to 'Applications > Accessories > Terminal' and find out your Ubuntu system partition by entering:

sudo fdisk -l

Notice: That is a lower-case 'L', not an upper-case 'I'.

You need to figure out your Ubuntu partition. If you are unsure, look for the size and formatting. Or running 'sudo blkid' might return a bit more relevant results.

In the above picture, sda1 is the Ubuntu partition. Once you figure that out, it takes 2 more commands to reinstall Grub.

sudo mount /dev/sda1 /mnt

Replace sda1 with your own partition.

sudo grub-install --root-directory=/mnt /dev/sda

Notice: For the second command, it is just 'sdX' without the partition number.

Once completed, reboot your computer. Remove the used Live CD/USB and hopefully you'll be able to boot into Ubuntu. If you intended to dual boot between Windows and Ubuntu and the Grub menu is not showing an entry for Windows, you need one more command, but this time, from your installed Ubuntu's Terminal and not from the Live CD/USB.

sudo update-grub

If the output lists Windows, you are ready to go. If you are still facing some problems, feel free to ask.


Related Posts:

Grub2 , Troubleshooting