How to boot a FreeBSD system in any partitions with loader.efi

In about FreeBSD 12.0-RELEASE, loader.efi has been used as UEFI bootloader instead of prior boot.efi.

Both loaders can boot a FreeBSD system from ZFS or UFS file system. The loader.efi only looks for the boot file system from the disk which the loader is loaded from, though the boot1.efi does it from its disk and also another disks. Briefly speaking, current loader.efi can't boot the system from other disks. Well, it can do it if we manually operate to set the boot devices in loader prompt each time, but this is not realistic way.

I thought that it somehow got be able to automatically boot the system from other disks, then I read some documents and googled, but there was no idea. After I reluctantly saw the source codes of loader.efi, I found a way using a loader.env file and a rootdev variable.

Regardless of loader.efi or boot1.efi, it eventually uses the value of currdev variable as a boot target. In loader.efi, the 'currdev' is set from a 'rootdev' variable unquestionably if it exists.

And then, it seems the rootdev is set by /efi/freebsd/loader.env file in ESP. This function is developed relatively recently, then FreeBSD 12.2-RELEASE and over support it.

Add a following line to the file to specify the file system path corresponding to root directory in ZFS. The value becomes like disk0p1 in UFS. Suffix colon is not wrong, it's necessary!

rootdev=zfs:zroot/ROOT/default:

They are undocumented as of 9th January 2021, so they may change in the future and also as-is.

Of course, I simply use prior boot1.efi with no need to such a chore way.

Thanks Decomo for this blog post. It helped me solve the booting problem in my FreeBSD 13.0 system using rEFInd boot manager. I created EFI/FreeBSD/loader.env with “rootfs=disk1p2” which is the FreeBSD root partition on the 2nd drive which worked! Thank you again.

1 |
Abraham Jose
| 2021-11-10 22:55 | reply

@Abraham Jose: A correction “rootdev=disk1p2”

2 |
Abraham Jose
| 2021-11-10 22:55 | reply

@Abraham Jose: Hi Abraham, it's my pleasure. For your information, it seems “rootdev” can be set by a options field in rEFInd's menuentry like as follows according to this post.

menuentry FreeBSD {
    loader /EFI/freebsd/loader.efi options "rootdev=disk1p2"
}

I didn't check it out, sorry if it's wrong.

3 | | 2022-04-04 10:31 | reply

We are seeing problems in UEFI mode for UFS GPT based box, I have a efi partition and which has /efi/EFI/BOOT/BOOTX64.EFI

and rootfs exists in partition 3 and partition 5.

I want to use boot.config to update currdev of loader to switch partition from 3 to 5, But setting the cat /efi/boot.config

0:ad(0p5)/boot/loader

is not working

I tried setting /efi/freebsd/loader.env , this also is not updating the currdev cat /efi/freebsd/loader.env

“rootdev=disk0p5:”

I am using FreeBSD 13.0-RELEASE-p11

4 |
Kavitha
| 2022-06-16 02:37 | reply



  • en/blog/2021/2021-01-09.txt
  • Last modified: 2022-01-06 13:04
  • by Decomo