June 01, 2008

Fixing the grub

You may manage to install Linux to run along with Windows using the easy to use interface that Ubuntu provides nowadays.But what happens if your hard disk crashes or some other hardware device fails.Or the usual troubles with Windows causes you to reinstall it.Now GRUB is effectively removed from your Master Boot Record(MBR).

Windows overwrites the GRUB(Grand Unified Bootloader) files from the hard disk's MBR,effectively making itself the only bootable OS in the system. On reinstall Windows,only this damage occurs to you Linux.No other changes come..you won't have to reinstall Linux.Now I will give you a step-by-step description of how to fix the boot-loader and return to the older condition where you could choose which OS to boot to.

Unless you need to urgently access the internet or run applications immediately,you can do this job after you have effectively restored your Windows install which might include installation of a huge number of drivers,applications and its configurations.You can also do the tweaking and modifications part and customize the Windows to be what it was before,if you are a person who likes OSes to be personalized.Surely I feel that way.It feels good when the way the system is arranged and managed reflects part of yourself.Ok..once you are done with all those activities,its time to give yourself the choice to go into a better OS.I will try to be as general as possible,but I can't help quoting examples from my system's cases:

1.Insert the Ubuntu cd into the drive and reboot.If you don't have the cd ready with you at the moment,stick to Windows for the time being and elongate your suffering even further.
Exit!!

2.Make sure the the optical drive you inserted the cd into is first in boot priority(No need to explain how to set this if you just finished re-installing Windows).

3.I am assuming you to be using version 6.06 or above(i.e Breezy Badger onwards).As you had once installed the same or newer version before,I am skipping the various options that you may need to provide for some systems(Like some systems like mine,need an option 'noapic' appended).

4.Once the live cd has booted up,(preferred over alternate cd) start the terminal.Go into root user mode by typing in 'sudo su'.

5.
Type 'grub' to enter the GRUB shell.You can refer to the exact device details if you wish to,either before you enter grub or in another terminal window using 'fdisk -l'.

6.Now,in the grub itself you can find which is the location the grub is installed,using 'find /boot/grub/stage1'.It returns a device string.

7.Type 'root' followed by the device string " (hd0,1) for eg" returned in the previous command.Press enter to make it the device where the grub is stored.Now your original GRUB configuration files would be read to perform the boot-loader operations.

8.Finish the actions by the command 'setup ("device")',where "device" is the device name part hd1/hd0 etc,which was returned by the find command.If you have only a single hard disk,its always hd0.Watch out for the confirmation and success messages.In case of errors,Google it,though the chances for error are minimum.

9.Type 'quit' to exit GRUB shell.Type 'reboot' or manually quit the live cd environment.Remove the disc and wait for system to reboot.The GRUB menu will reappear as before and now you have restored your system to previous condition.

Few things to keep in mind and hand when you have multi-boot systems:
a)Have multiple copies of bootable cds(either OS).
b)Have and idea about device and partitions in the system.
c)Re-installation of either OS affects only the boot-loader unless you decide to modify the partitions owned by the other OS.
d)Always backup important data,emails and software installation packs(also their configuration files) to a secure location(External hard disks,dvd/cds,or network storages).
e)Keep in touch with one or two people who are good at troubleshooting in both the OSes involved(i.e you yourself are not one).Forums can also help.

That's it for now.Suggestions are welcome and if you find any mistakes in my approaches or if you want to comment,please do post it.

1 comment:

Anand.V said...

Hey thnx a lot man, this really worked. I had vista n ubuntu on my system and i replace vista with xp, and the grub was gone. These instructions were really cool and the grub is back n i can access ubuntu now. Thnx again!