Grub2 and drives that move

I recently built a new machine to server as my home-office network server. This box has 24 hot-swap bays, and I tend to use them for all sorts of storage configurations.

It’s nice to be able to shove a couple of disks in from another machine, recover software RAID and generally shunt data around in bulk and at speed. The issue I’ve found with this relates to the new uEFI BIOS this motherboad comes equipped with.

It appears that it’s not uncommon for my drives to move around in the BIOS order depending on what is plugged into the machine at the time. This makes a default Grub2 install particularly unhappy and often results in a box that just won’t boot.

Fortunately, Grub2 comes with the ability to embed modules and a configuration file directly into the stage 2 binary. As appears customary, the generic userspace tools don’t make this feat particularly intuitive, thus this post.

First I created 2 files. The uuid in the first file was obtained using “blkid”

root@test:/root/grub2# cat grub.core.config
search.fs_uuid root 29f53f33-f452-4382-b598-ee307a65f360
set prefix=($root)/grub 

root@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.

Incidentally this works nicely when installing on a RAID-1 with a version 0.90 superblock as the first partition on the boot drives.
Note I’m using a separate /boot partition that is plain ext2 and therefore the grub files are at /grub rather than /boot/grub.

Comments are closed.