Wednesday, April 12, 2006

Restoring grub for debian

Many Debian newbies often have to reinstall f***ing Windows on the same machine where Debian is installed. Usually the Windows installation does not take care of the Debian booting process, overwriting the master boot record with Windows.There are several ways to recover the grub , but here I will mention the method used by me when I had the same problem.


All that you would need for this is a live CD of any debian based Linux distro like Ubuntu or Knoppix.Once u have a live CD with you just follow the next few steps.
  • Boot from the Live CD( I used Ubuntu CD)
  • Once you are logged in open the terminal.
  • Login as root (type sudo su in Ubuntu) and type cfdisk and check out what is your boot partition (eg. hda8)
  • Make a new directory to mount the boot partition, for example /disk.
  • In case you don't have seperate /boot partition then mount the root partition or / to /disk using the following command

    mount /dev/hda
    x /disk

    x refers to teh boot or root partition.
  • Do a chroot to the root partition by typing

    chroot /disk

  • Type grub and enter grub shell.
  • Type in the root disk for grub, for example

    root (hd0,7)

    This is /dev/hda8 on my system.
  • Type the following command to install grub on /dev/hda

    setup (hd0)

  • Type quit, exit from chroot, unmount all disks and reboot.