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. 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. Go through all the prompts (no network connection is required), up until mounting the root partition. When prompted for the root partition 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 /dev/sdXN /mnt
    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 -B /dev /mnt/dev
    mount -B /proc /mnt/proc
    
    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. If not, 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