Tuesday, January 10, 2012

Fix boot problems - Grub 2

Here is a quick how-to guide on how to fix Grub2 without a liveCD. There are many possibilities on how to break it in the first place, but the most common one is setting up new partitions on a secondary OS - eg. setting up partitions in Windows, while the bootloader is indeed Grub. Doing this will most likely make it impossible to boot up your OS's in a normal way.



Here is what you need to do:

When you boot up this will appear if Grub 2 was not able to find its folder or load a module:

grub rescue>

(*Note "grub>" appears if modules were successfully loaded, but the grub.cfg file in the boot process)

You can type in "set" to see current setting.

To find out your partition table do:

ls

They will be noted in a format similar to this: hdx,y (where x is the disk, and y is the partition - this might be relevant to you if you have more than 1 disk).
Find the partition with your Ubuntu/other linux installation and write it down to a piece of paper.

Do the following command, and input your partition:

set root (hdx,msdosy)

(eg. set root=(hd0,msdos3) or set root=(hd0,sda3) etc.. depends what you have)

We will now be setting the prefix, determining where is the boot folder. Usually it is one the same partition as your OS, so use that.

set prefix (hdx,msdosy)/BOOT LOCATION

(eg:set prefix (hdx,msdosy)/boot/grub)

Write this to load the normal module:

insmod normal

Now we attempt to activate the normal module. Grub 2 menu should appear if all went good. Write this:

normal

After successfull boot to your OS, be sure to do the following in Terminal:

sudo grub-install --boot-directory=/boot/grub /dev/sda

Voila, you fixed your Grub 2. This is ofcourse much easier with a LiveCD, because the only thing you need to do is mount your filesystem and do the grub-install command.

6 comments:

  1. One usefull tip: We can change order of systems.
    here is config file:
    sudo gedit /boot/grub/grub.cfg

    ReplyDelete
  2. Interesting. Thanks for the share!

    ReplyDelete