Restore Debian Linux Grub boot loader

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).

ADVERTISEMENTS

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 😀

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source & DevOps topics via:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
17 comments… add one
  • krishnakumar Jan 22, 2008 @ 7:39

    very nice comment

  • krishnakumar Jan 22, 2008 @ 7:40

    very nice thank u

  • danuthaiduc Feb 5, 2008 @ 10:05

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

  • raf Apr 11, 2008 @ 18:49

    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

  • rc Jul 5, 2008 @ 7:10

    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

  • davidb Sep 1, 2008 @ 14:54

    thanks, good instructions.

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

  • Anand Oct 7, 2008 @ 7:52

    i forgot my linux root password.

    so. solve me

    root password……….

  • Ankur Apr 24, 2009 @ 14:31

    Anand !

    Go here

  • suresh Nov 9, 2009 @ 14:09

    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..!!

  • l4mer Feb 12, 2010 @ 9:40

    I had:
    not found or not a block device.
    message.
    So, next I create node for my /dev/hda
    mknod /dev/hda 3 0
    mknod /dev/hda5 3 5

  • Bjoern Jun 12, 2010 @ 13:47

    Phew, thanks!. Managed to clone my old disk and now running my old Debian install on my new disk.

  • LYNXLUNX Jan 24, 2011 @ 2:04

    Several users have noted that when they chroot into the special directory, and run grub-install, they receive this warning: ‘not found or not a block device’. Also, these users will notice that the devices haven’t been discovered in /dev/

    To solve this problem, make sure udev is picking up those devices. Do this instead:

    # mount -o bind /dev /mydisk/dev
    # mount -o bind /proc /mydisk/proc

    Now chroot into the new directory
    # chroot /mydisk

    Run the grub reinstall
    # grub-install /dev/hda

    For those users who chroot into the mounted directory, and run the grub-install command only to be left with the message:

  • Oti Sep 20, 2011 @ 16:11

    Thank you very much !
    It’s the first tuto that works for me, there’s an awful lot of topics that do not even mention the “chroot” part…

  • LineshJose Feb 19, 2012 @ 13:32

    Nice tut. thanks bro. you saved me 🙂

  • Thomas Jobe Lawnmowerman Mar 31, 2012 @ 9:25

    A very nice tutorial which is still valid today.
    This was the howto which got me onto the path of solving my non-booting Debian Server (Sqeeze).

    After loading up the Debian-CD rescue mode and entering the rescue shell
    update-grub2 would not run.

    launching /sbin/bash is a good idea by the way

    There is one thing you could have mentioned which I had to do in order to rescure my system. I had to manually mount the /boot paritition and then update-grub2
    worked perfectly.

    Thanks a lot mate

  • debman Aug 13, 2013 @ 17:48

    I can has Tunderbird???

  • dave Oct 5, 2014 @ 1:03

    After grub-install I get the error “bash: grub-install: command not found.”

    Grub-install is available before the chroot. Apt-get install grub does not work after the chroot. I’m stuck.

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.