Restore Debian Linux Grub boot loader

by LinuxTitli · 9 comments

Recently my hard disk went bad (some bad sectors developed), my boot.ini (Windows XP boot file) corrupted. I was using NT boot loader to load Linux. So I need to repair the Grub i.e. restore Grub in master boot record (MBR).

Today is national holiday (I-DAY) and I wanna watch TV. Problem is neither I can boot to Linux nor using XP. So I just took my Debian GNU/Linux DVD and booting started when I had presented installation option (after networking dialog prompt) :
1) Press ALT+F2 (or ALT+CTRL+F2) to get shell prompt
2) Then get the partition tables for the devices using fdisk command:
# fdisk -l

3)When you type fdisk -l, you should see your partition name: /dev/scsi/host0/bus0/target0/lun0/part1 (for IDE disk it display same device file in IDE directory)

4)Once you identified your device file, mount disk using mount command:
# mkdir /mydisk
# mount /dev/scsi/host0/bus0/target0/lun0/part1 /mydisk

5) Next use chroot command to start interactive shell with special root directory i.e. /mydisk will act as root directory.
# chroot /mydisk

6)Use grub-install command to reinstall grub (SCSI disk):
# grub-install /dev/sda

If you have IDE device following command :
# grub-install /dev/hda

Again replace /dev/hda and /dev/sda with your actual device names.

7)Type exit and reboot the system. You should see your GRUB and Linux again.
# exit

Other choice was to use Linux Live CD (e.g. Mepis) and do the above procedure. Well, I could have used the Mepis to watch TV but I had some data and emails in Tunderbird so I opted to restore the Grub; watched TV, took backup of emails and now I will put new 120 GiB hard disk tomorrow :D

Featured Articles:

Want to read Linux tips and tricks, but don't have time to check our blog everyday? Subscribe to our daily email newsletter to make sure you don't miss a single tip/tricks. Subscribe to our weekly newsletter here!

{ 9 comments… read them below or add one }

1 krishnakumar 01.22.08 at 7:39 am

very nice comment

2 krishnakumar 01.22.08 at 7:40 am

very nice thank u

3 danuthaiduc 02.05.08 at 10:05 am

Saved my life! luckily i had a LiveCD to be able to read this…
Thanks!

4 raf 04.11.08 at 6:49 pm

I have a problem regarding dual boot (vista & ubuntu) when successful in installing ubuntu, I can’t boot to vista, only ubuntu. It said virus:….. Is it like a boot virus? how to fix that? thank you

5 rc 07.05.08 at 7:10 am

I’ve been following your instructions but it does not work. Since I chrooted to the mounted /dev/sda2 (where grub sould be installed in /boot) grub-install looks for the device file (/dev/sda) in the chrooted dir and thus returns an error; /dev/sda: not found or not a block device. Which makes sense because I did not boot to sda so the /dev/sda device file was never created.

By the time you read this (hopefully) I’ll have it fixed, but would like to know what I’m not getting just for curiosity sake. Will be checking back.

thanks

6 davidb 09.01.08 at 2:54 pm

thanks, good instructions.

though, you should probably unmount the drive before restarting (though it really isn’t that important).

7 Anand 10.07.08 at 7:52 am

i forgot my linux root password.

so. solve me

root password……….

8 Ankur 04.24.09 at 2:31 pm

Anand !

Go here

9 suresh 11.09.09 at 2:09 pm

Hi..
I tried to restore grub by using the debiam rescue mode…This time I lost windows..!!While selecting windows it is again loading Grub Stage2 and showing the grub menu again….Please help me out..!!

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Previous post:

Next post: