Rescuing a trashed GRUB 2 bootloader on Debian

By: ALLurGroceries

Possible symptoms/causes:
  • Reboot loop
  • Error messages
  • grub> prompt
  • Stuck at "Loading stage X"
  • A bug in GRUB 2 itself
  • Installing Windows (or another OS) after GRUB 2 or wiping out the MBR by other means
  • Changes in hardware setup or non-catastrophic hardware failure

    Find (or download) your copy of the installation media (Lenny or later) and boot with it. Make sure it is for the same architecture that is already installed (e.g. i386, amd64) or this guide will not work. If no CD/DVD drive is available try UNetbootin to boot from USB. For other methods of booting the installer, such as over a local network, see Booting the Installation System.

    At the boot menu select Advanced Options and then Rescue Mode. Select your language and keyboard layout, no network connection is required. When it prompts for an ethernet card, disregard it and hit ALT+F2 and hit Enter to get to a shell.

    Find your root and boot (if applicable) partition(s) with:

    fdisk -l
    Mount the root partition to /mnt, where X is the letter of the disk and N is the partition number:
    mount -t ext3 /dev/sdXN /mnt
    (if necessary replace ext3 above with ext4)

    If you have a separate boot partition, mount it to /mnt/boot:

    mount /dev/sdXN /mnt/boot
    Remount the rescue environment's /dev to /mnt/dev and the same for /proc:
    mount --bind /dev /mnt/dev
    mount --bind /proc /mnt/proc
    mount --bind /sys /mnt/sys
    mount --bind /dev/pts /mnt/dev/pts
    
    chroot into the target disk's fs:
    chroot /mnt
    Reinstall grub and force a probe of the device map in case there are changes, where X is the disk letter:
    grub-install --recheck /dev/sdX
    If the device map does not match (or none exists), grub-mkdevicemap should be run.

    Run update-grub in case the configuration file has gone bad (or missing):

    update-grub
    Exit from chroot with Ctrl+D and reboot with Ctrl+Alt+Del. Your system should hopefully boot to the GRUB 2 menu again.

    For Windows XP/2000 dual boots: the grub2 version shipped with Lenny does not have a script for booting Windows OS versions prior to Vista. In this case, boot Linux from your hard disk and re-run grub-install and update-grub. Newer versions will recognize XP.

    If you still can't boot for some reason, here are some links to lead you in the right direction:

    GNU GRUB 2 Manual "Panic!" section
    Error messages reported by GRUB (0.97)
    Super Grub Disk Wiki "Boot Problems" section
    Debian Installation Guide, Chapter 3, Section 6: Pre-Installation Hardware and Operating System Setup
    Debian Reference, Chapter 3: The system initialization
    UNetbootin, a utility for both Linux and Windows for creating bootable USB media from ISO images