After the kernel is loaded can't you just check where the root filesystem is mounted from? It's in the output of
mount(8).
That tells me where the system thinks it is but not where the EFI loader thinks it is. And they're not necessarily the same.
Consider a box with a nVME non-bootable device in it you wish to boot from an SD card or USB stick. This under NanoBSD makes for a power-fail-safe device (no risk of the filesystem being inconsistent if the cord is yanked.) For a firewall appliance this is desireable.
Now I want to update the code partition. I have the running one which I can't stomp on, and I know what that is from FreeBSD's perspective so writing the update code to the other one is easy.
But having the loader point at the right one is not. That's the problem, since, for example, the running system here is on /dev/da0s1a however the EFI loader booted it from disk1, not disk0 because disk0 is not bootable.
What I have right now will boot on either a legacy box with no EFI at all (since it has boot0/bootcode on it) or an EFI box. Plug it in, both like it. This is good. And on the legacy box its easy since you just set the active flag on the right partition. The Nanobsd changes made quite some time ago got this sort of but lost the data partition which I resolved by putting it in a BSD partition for the 4th MBR slice.
But on the EFI box its not that simple since the loader, without being told otherwise, will boot the first bootable thing it sees.
you can examine loader's currdev and loaddev with kenv
Not so sure about that:
Code:
$ kenv|grep disk
currdev="disk0s1a:"
loaddev="disk0s1a:"
Except its not from the loader's point of view at boot time before it loads the kernel.
I stuck "disk0s2a" in loader.env (which is correct if the loader thinks the USB key is "disk0") and the EFI loader chucked on it when a reboot was attempted. Listing the devices from the loader showed the nVME drive as disk0 which has no bootable partition on it. Manually setting currdev was successful but apparently what the kernel thinks it has now and what the loader on the EFI partition thinks the disk number is differs, and in order to update the loader.env file in the script I need to know what it wants and be able account for the order in which it the EFI loader will enumerate the devices.
Been scratching my head a bit on this one as I figured I could find it in the kernel environment and it would be the same, but it isn't.
This is what the system says once running with gpart:
Code:
$ gpart show
=> 40 250069600 nda0 GPT (119G)
40 67108864 1 freebsd (32G)
67108904 182960736 - free - (87G)
=> 40 250069600 diskid/DISK-BKHD-G20250410045 GPT (119G)
40 67108864 1 freebsd (32G)
67108904 182960736 - free - (87G)
=> 63 60125121 da0 MBR (29G)
63 11257500 1 freebsd [active] (5.4G)
11257563 11257500 2 freebsd (5.4G)
22515063 81920 3 efi (40M)
22596983 840517 4 freebsd (410M)
23437500 36687684 - free - (17G)
=> 0 11257500 da0s1 BSD (5.4G)
0 16 - free - (8.0K)
16 11257484 1 freebsd-ufs (5.4G)
=> 0 11257500 da0s2 BSD (5.4G)
0 16 - free - (8.0K)
16 11257484 1 freebsd-ufs (5.4G)
=> 0 840517 da0s4 BSD (410M)
0 62500 1 freebsd-ufs (31M)
62500 750000 4 freebsd-ufs (366M)
812500 28017 - free - (14M)