mercredi 9 décembre 2009

How-to: restoring Grub2 on Debian


Debian recently chose to switch from grub1 (now grub-legacy) to grub2 (now grub-pc).
Those who upgraded their Debian Unstable/Sid recently might have suffered from annoying "Error 15" on boot, mostly due to grub2 being unable to read its files.

Here's the classic mount-chroot-restore method to fix that kind of problems.

1. fetch pre-requisites
You need a bootable Debian Install medium (CD, USB stick, network boot, etc), the smallest (business card) will do.

2. boot your media

3. choose "rescue mode", select lang and keyboard and switch to vt2 (Ctrl-Alt-F2)

4. mount your disk(s) partitions


$ cat /proc/partitions
...
$ modprobe ext2 # load whatever you need, ext2, xfs, etc
$ mount /dev/hda2 /mnt # your root partition first
$ mount /dev/hda1 /mnt/boot # your boot partition if one
$ mount /dev/hda5 /mnt/usr # ...etc
$ mount -o bind /dev /mnt/dev/
$ mount -o bind /proc /mnt/proc
$ grub-setup --force '(hd0)' # this will install grub with some warnings
...
$ reboot


5. you're done !

PS: you may want to read http://wiki.debian.org/GrubTransition on the Debian Wiki.