Monday, January 12, 2015

Repair GRUB2 When Ubuntu Won't Boot

If you have a dual boot system in your computer and if you have installed windows after ubuntu you may not able to log in to ubutnu because you MBR might be changed or overwritten.
Ubuntu and many other linux distributions use the GRUB2 boot loader. In that case you have to restore GRUB2 from a ubuntu live CD or USB drive.
There are two main methods to do this. One is Boot Repair graphical tool that can repair GRUB2 with single click. But i think most suitable way for most cases is use ubuntu terminal to restore GRUB2.

lest see how to restore the GRUB2
first you'll need to boot from a live CD or USB drive. Make sure that version of ubuntu in your live CD or USB drive is the same as the version of ubuntu installed on your computer.  As a example if you have installed ubuntu 14.04 you have to use live CD of ubuntu 14.04.

then open a terminal after booting in to the live environment. Use sudo fdisk -l command to identify the partition ubuntu is installed.

Then Use the following command to mount the ubuntu partition at /mnt

sudo mount /dev/sdX# /mnt

you should replace sdX# part with the device name of your ubuntu partition.
as a example, if the ubuntu installed partition is 'sda6' the command should be  'sudo mount /dev/sda6 /mnt'

Important: if you have a separate boot partition, skip the above command and mount the boot partition at /mnt/boot. if you don't know weather you have a separate boot partition , you probably don't.

Then use the following command to reinstall the GRUB2 from the live CD or USB drive, replacing the dev/sdX with the device name of the hard disk above.Omit the number.
for example if you used /dev/sda6 above use /dev/sda here.

sudo grub-install --boot-directory=/mnt/boot /dev/sdX

Finally restart your computer.
now ubuntu GRUB should be displayed and ubuntu should boot properly.


No comments:

Post a Comment

Optimize you working enviorenment : Single command to create & move to a directory in linux (C Shell, Bash)

Usually move to a directory just after creating is bit of a anxious task specially if the directory name is too long. mkdir long-name-of...