Just added my solution for getting the boot drive from the root variable using regexp and it works like a charm.
I’ve added the line " regexp --set “mender_grub_storage_device” “(\w+)” “${root}” " (without the first and last quotes) just below “# load environment” section and now it doesn’t matter what other mass storage devices are plugged into the USB ports, it will boot to the currently active rootfs partition.
The only strange thing I do see is that I get the message “error: variable prefix not set” during the Grub section (between the grub greeting and the the two lock messages". I’ve added an echo statement for prefix just before the “# load environment” section to print the actual value and that didn’t show anything out of the ordinary (it shows the correct prefix). Looking online for this error I see posts that this is something that can happen but isn’t something to worry about.
If anybody has tips or tricks to avoid/remove this error I’ll be grateful as it does give you the impression that something is wrong.