Wednesday, April 30, 2008

How to:Restore an over written GRUB boot partition:

Hi guys, sometimes when we install a fresh copy of Windows or even repair windows, the MBR gets overwritten leaving us stuck with only windows and no way to access our dah'lin linux system. Here I have tried to present a short HOWTO on how to get back your all O.S. in bootable form through grub after windows install, repair or whatever...



Step 1: Boot from a live CD

(Why: booting from a live CD puts you in a linux environment with root privileges which are needed to edit grub)

Step 2:
Execute the following in the terminal without the $ sign... $ stands for the prompt(similar to c:\> in windows)
(Applications->Accessories->Terminal )

$sudo -i

(Why: sudo -i converts the current terminal session into root session.You wont have to attach sudo before every command)

Step 3:
Execute

$grub


This will put you to the Grub shell

Step 4:
Find your previous bootable linux partition by


grub>find /boot/grub/stage1

Suppose you get:
(sd0,7)
which meens that in the drive that is referenced at sd0, the partition is the 7th partititon.
you may get different outputs of the type (disk_code,num)
so in the following steps, replace the disk_code by your actual disk code( hd0...sd0...sda... etc) and num by your partition number.
DONT BLINDLY COPY !!! :-p

Step 5:
Reset back the root partition to the original partition by executing:

grub>root (disk_code,num)

(Dont forget to substitute the values of disk_code and num )


Step 6:
Install grub starting with the MBR by executing:

grub>setup (disk_code)

This will install part of the bootloader into the MBR and the main parts into the partition where your linux is installed.
Again...Dont forget to substitute the values of disk_code and num )

Step 7:
Assuming all went well, give yourself a pat on the back as you hav just reinstalled the bootloader and stopped yourself from making the idiotic mistake of format-and-install-again-and-again.... :-)

Now for the last parts...execute

grub>exit

(Why: Simply to quit grub and go back to the main prompt for the last step)

Step 8:
Restart the system either by the graphical way (System->Shutdown->Restart ) or the terminal by executing

$reboot


easy huh???
watch out for a howto on the basics of editing the grub's menu file (menu.list).....coming soon...