[plug] grub2 and the mystery of the moving hard drives
Brad Campbell
brad at fnarfbargle.com
Fri Mar 16 19:15:59 WST 2012
G'day all,
I'm in the process of building a new server. It has 24 drive bays and a
peculiarity of the system firmware appears to be when I add or remove
drives, the boot drive moves around in the BIOS order. This means that
grub2 can rarely (if ever) find the drive its modules are stored on as
its root directory is hardcoded at install time. Why it can't find it is
a mystery to me given its stage 1 just loaded stage 1.5 from the boot
track, but never mind.
After spending days fighting with this rotten thing booting of USB
rescue disks to re-install grub, I stumbled across this little trick.
grub2 can have a config file embedded in its core image. Now, as is
typical, how you get it in there is not particularly obvious.
Frustratingly grub-install has no way of letting you pass a config file
to embed, however grub-mkimage does. grub-install has a way of letting
you override which grub-mkimage it uses.
I created 2 files.
root at test:/root/grub2# cat grub.core.config
search.fs_uuid root 29f53f33-f452-4382-b598-ee307a65f360
set prefix=($root)/grub
root at test:/root/grub2# cat test
#!/bin/sh
grub-mkimage -c grub.core.config $@
Then installed with
grub-install --grub-mkimage=./test /dev/sde
Bingo. Grub now has its uuid search algorithm embedded along with the
config file and the first thing it does is search all accessible
partitions for the uuid and uses that to access its files. I can happily
rearrange disks with gay abandon and the system boots every time.
Note I'm using a separate /boot partition that is plain ext2 and
therefore the grub files are at /grub rather than /boot/grub.
I wish this was documented somewhere obvious.
Regards,
Brad
More information about the plug
mailing list