Place Ghantoos

Debian: restore grub on sd{a,b} using grub-mkdevicemap and grub-install


I had to reinstall grub on the MBR of one of machines. After resizing a GPT partition, and actually writing the changes on the disk’s partition table, my MBR was erased (the MBR is controlled by the GTP partition table), thus removing my dear grub.

Anyways, after rebooting my machine using the Debian Installation disk, I discovered that my disk were named differently: /dev/sda was renamed to /dev/sdb (classic!). Unfortunately, I struggled with grub-pc, grub-install, grub-update, update-grub to restore my grub information to the MBR, with no success.

I then found out that the file (/boot/grub/ was pointing to the wrong disk name.
So here is what I did to get over the disk renaming craziness and restore grub to the MBR.

(info: The running distribution on the server was a Debian Lenny, and I used a Debian Squeeze installation disk to rescue it.)

First, I mounted my partitions the chrooted to them:

~# mount /dev/sda3 /mnt/
~# mount /dev/sda1 /mnt/boot
~# chroot /mnt

At this point, inside my chroot, my disks appeared as /dev/sda and /dev/sdb.
I had to rewrite the grub file in order to make it point to the new disk names.

~# grub-mkdevicemap

Then, in order to restore grub to the MBR:

~# grub-install /dev/sdb
~# update-grub

Reboot the machine. Then, re-run the above commands to restore the original grub configuration:

~# grub-mkdevicemap
~# update-grub

I wrote this small tip, as a reminder for myself. Anyways, I hope this helps.

Ignace M


Leave a Reply