Gigabyte Brix issues with mender i.c.w. Ubuntu Server 19.04

I’ve been doing some experiments with Grub and booting with the 4G USB stick inserted. I see that the internal SSD has been shifted to (hd2) because the stick introduced both an (hd0) and a (hd1) drive in the mix, with (hd0) being presented as a drive with ISO9660 filesystem (basically it imitates a CD) and (hd1) being an invalid drive (ls (hd1) returns an invalid sector size error, most probably because it tries to access the integrated SDCard reader which has no card inserted).

Looking at the environment variables that are set I see that all Mender related ones seem to be aware that their files are stored on (hd2,1), which makes me wonder if it is possible to change the grub script in such a way that it also uses the boot drive reference (called prefix in the grub script) in a way that would allow it to modify the partition part from 1 to the relevant rootfs partition (so 2 or 3)?

That way there is no need for specifying UUIDs of filesystems or partitions and the grub config would still be robust against drive letter shifts.

Since I’m not an expert on what can and can’t be done in Grub2 scripts (total noob here), maybe someone with more advanced knowledge of Grub2 can tell me if something like that is possible?

– edit –

I’ve looked around on the internet and it seems that there might be a way to do this by using the regexp command. According to a post here:

it should be possible to extract the first part of the string of either prefix or root (that contains only the drive/partition pair, so should be less error prone to process that variable) using a regular expression.

Testing some regex online (hopefully using the same syntax as the Grub2 one command uses I found one that will capture the entire string up to the partition number. It is:

.\w*.\D+

The result of this pattern for the “(hd0, msdos1)” string is everything up to the 1 (so “(hd0, msdos” is the result for this case). I’ve also tried this out for other variations like “(hd0, 1)”, “(hd0,1)”, “(hd0,msdos1)”, “(hda, msdos1)” and all those worked. I don’t know if there are other variants that Grub2 will use for other device types, maybe someone with more knowledge of Grub2 can check if the pattern would cover all those cases.

If it is possible to use the “regexp -s varname pattern subject” command in the grub.cfg file to capture the first part of the boot drive, it should be possible with the string composing functionality to create the correct partition “id” to use for booting to the active partition as set by mender.

I haven’t been able to test the above solution because when I get dropped in the Grub 2.04 shell it seems that a number of commands (including regexp) are not available. I guess that someone has decided to reduce the size of the Grub2 interpreter for use with Mender.