Sunday, December 23, 2007

Recover the Linux Boot Loader (Grub)

Most of the Linux users who are using multiple operating systems installations in a single hard drive. Many of them (Especially those of Microsoft's) have to encounter the erasure and re-writing of MBR (Master Boot Record) after re-installing or fresh installing Windows after Linux. This situation is very frustating as despite the Linux partition being intact, one has to reinstall the Linux distribution everytime after installation of Windows.
By issuing the below commands, one can retrieve his/her previous Grub Bootloader screen in 6 easy steps.
Prerequisites:
  • You need a bootable Linux CD (Preferably a live CD)
  • Please note that the Linux partiton for which you are going to recover the MBR should be installed on an un-encrypted filesystem
Stpes:
  • Boot with the bootable linux CD
  • Invoke the shell
  • Give the following commands
  • # grub (This will drop you on the grub prompt)
  • grub>geomettry (hd0) (Your Primary Hard Drive. Determine the Linux Partition number say "n")
  • grub>root (hd0,n) ("n" is your linux partition searched by the previous command)
  • grub>setup (hd0,n)/boot/grub/menu.lst
  • quit

Voila!!.... just restart your computer and find your previous MBR restored!!

Google Search