tl;dr: I want to adapt this:
to automatically boot from the highest available disk.
Background
I recently bought a HPE Microserver Gen8 to act as a backup server for my parents (and also as an offsite backup for me). It’s a nice little piece of kit–small, quiet, energy-efficient, but still with a decent amount of CPU horsepower and four drive bays. And pretty reasonably priced on the used market.
The system has a fifth SATA port that serves an optical drive, but due to some curious decision-making on HPE’s part, it will not boot from that port. And it’s also a little picky about USB boot devices, so I wasn’t able to just install TrueNAS to a USB SSD and boot from that (at least, not with the USB SSD I had around).
Enter the forum thread I linked above–that user came up with a clever way to handle this, by installing Grub to a flash device (I used a microSD card, since the system has an internal reader for those), and then, using a hand-coded grub.cfg
file, telling Grub to continue booting from the SSD where I had TrueNAS installed. So I can boot from a SSD (rather than what tend to be very unreliable USB flash drives), but it doesn’t have to occupy one of my four drive bays that I’d rather be able to use for storage.
The grub.cfg
, as I’ve slightly modified it, goes like this:
set default="0"
set timeout=5
menuentry "TrueNAS CORE 12" --class freebsd --class bsd --class os {
insmod zfs
insmod ext2
insmod part_gpt
echo Chainloading hd3 ...
set root=(hd3)
chainloader +1
}
The problem
If you look carefully above, you’ll see that it’s booting from a hard-coded hd3
, the third drive on the system (right now, I have two spinners plus the SSD; the SSD is the third drive). And this is fine for right now, as there are only the three drives. But if I need more storage in the system, I’d install another pair of drives, and the SSD will then become hd5
–and now it won’t boot without editing that grub.cfg
.
What I’d like to be able to do is tell Grub, “boot from the last drive.” To narrow it down, I could say, “boot from the last drive of hd{1…5}”, as this system has only the five ports. But a web search is finding almost nothing about preparing your own grub.cfg
file–everything I’m finding says “here be dragons, don’t do it, let your system generate it automatically”, which just isn’t very helpful here. The Grub manual on gnu.org suggests that it does support conditional logic and looping:
GNU GRUB Manual 2.06
But I don’t see anything there, or anywhere else I’ve seen, to do anything like what I’m wanting to do. Any ideas?