Solved loader.efi in EFI is not able to boot FreeBSD 13.0

I have upgraded from 12.2 to 13.0 and rEFInd detects FreeBSD/boot1.efi in ESP partition and can boot into FreeBSD. However, when I tried with copying /boot/loader.efi into the ESP partition FreeBSD folder, it is not booting. It is showing below error. Note that ESP partition is in SSD and FreeBSD resides in HDD.
This is what I see, when booting using loader.efi:
index.jpeg
 
Is there a way to get loader.efi to detect the FreeBSD root partition? Here is my storage details:

Code:
% doas gpart show    
=>       34  351651821  ada0  GPT  (168G)
         34       2014        - free -  (1.0M)
      2048     411648     1  efi  (201M)
     413696   77594624     2  linux-data  (37G)
   78008320  209715200     3  linux-data  (100G)
  287723520    4194304     4  linux-swap  (2.0G)
  291917824   59734031        - free -  (28G)

=>        34  1953525101  ada1  GPT  (932G)
          34           6        - free -  (3.0K)
          40    94371840     1  freebsd-ufs  (45G)
    94371880   139083736     2  freebsd-ufs  (66G)
   233455616   565602304     3  linux-data  (270G)
   799057920   333328384     4  linux-data  (159G)
  1132386304    82550784     5  linux-data  (39G)
  1214937088    87396352     6  linux-data  (42G)
  1302333440   329502720     7  linux-data  (157G)
  1631836160   102656000     8  ms-basic-data  (49G)
  1734492160   190455125     9  ms-basic-data  (91G)
  1924947285         683        - free -  (342K)
  1924947968      976896    10  ms-recovery  (477M)
  1925924864        2048        - free -  (1.0M)
  1925926912       32768    11  ms-reserved  (16M)
  1925959680     2097152    12  freebsd-swap  (1.0G)
  1928056832    25468303        - free -  (12G)

ada1p2 is the root and ada1p1 is the /usr/home partitions. ESP partition is ada0p1.
 
I managed to boot into FreeBSD successfully by using set currdev=disk1p2 and followed by boot. Is there a way to persist this change?
 
Yes. Look at /boot/defaults/loader.conf, or loader.conf()

I think you can add kernel environment variables in that file, e.g. add currdev="disk1p2" to /boot/loader.conf
It did not work. I tried putting in both /boot/loader.conf and also /boot/defaults/loader.conf (which is a read only file).
 
What happens with efibootmgr?

Code:
efibootmgr -v

BootNext: 0002

BootCurrent: 0001

Timeout: 1 seconds

BootOrder: 0001,0002,0000,0008,0005

Boot0000* Windows Boot Manager    HD(1,GPT,1038f5a8-2ee4-4dff-8d26-2e2c2bf3cbee,0x800,0x64800)/File(\EFI\Microsoft\Boot\bootmgfw.efi)WINDOWS.........x...B.C.D.O.B.J.E.C.T.=.{.9.d.e.a.8.6.2.c.-.5.c.d.d.-.4.e.7.0.-.a.c.c.1.-.f.3.2.b.3.4.4.d.4.7.9.5.}...v................

Boot0001* rEFInd Boot Manager    HD(1,GPT,1038f5a8-2ee4-4dff-8d26-2e2c2bf3cbee,0x800,0x64800)/File(\EFI\refind\refind_x64.efi)

Boot0002* FreeBSD    HD(1,GPT,1038f5a8-2ee4-4dff-8d26-2e2c2bf3cbee,0x800,0x64800)/File(\EFI\FreeBSD\loader.efi)

Boot0008* UEFI: INTEL SSDSC2    PciRoot(0x0)/Pci(0x1f,0x2)/Sata(0,65535,0)/HD(1,GPT,1038f5a8-2ee4-4dff-8d26-2e2c2bf3cbee,0x800,0x64800)/File(\EFI\BOOT\BOOTX64.EFI)
 
I have since rearranged boot order, removing Windows boot manager entry which was booting into Windows 11 before rEFInd. rEFInd auto detects all the entries including FreeBSD/loader.efi located in ESP partition.
Code:
Timeout: 1 seconds
BootOrder: 0000,0009
Boot0000* rEFInd Boot Manager
Boot0009* Hard Drive
Still, did not find a way to make loader.efi "see" the other hard drive where FreeBSD root partition resides. :(

But, few problems I still face is - pcm4 sound device (Intel Cougar point) dies out, No video play in browsers or in VLC. I have no idea why this is happening. Yes, graphics (Intel onboard) acceleration is working. These were working fine in 12.2. It was an upgrade from 12.2 to 13.0 Release.

Since you are using rEFInd, try options "rootdev=disk1p2" in refind.conf. Reference:
I tried this as well as currdev option with manual FreeBSD entry in refind.conf. It did not boot. Is there a way to regenerate loader.efi to identify the disk which contains FreeBSD root.
 
Does your upgraded FreeBSD system have the file /boot/lua/loader.lua? Your first post's photograph suggests that it might be missing. Maybe it got lost in the upgrade? Or maybe it wasn't present on FreeBSD version 12.2? I ask these questions tentatively, because I'm just guessing at the problem, and don't actually know.

I don't use rEFInd and don't understand it well. For multi-boot systems, out of old habits, I use grub instead. Debian's version of grub uses loader.efi, but after recent changes (earlier this year), the Ubuntu version of grub now requires me to use loader_4th.efi instead of loader.efi.

I don't understand exactly why. Some time ago, I read somewhere on this forum that FreeBSD is in the process of transitioning from the Forth (4th) loader to the lua loader, and was given the impression that the Forth loader was deprecated. Hope this helps rather than adding to any confusion. Maybe loader_4th.efi might work for you as a temporary workaround?
 
I read somewhere on this forum that FreeBSD is in the process of transitioning from the Forth (4th) loader to the lua loader, and was given the impression that the Forth loader was deprecated.
From 12.0 onward the LUA loader has been the default. The Forth loader is still available on 13.x, it will probably be removed with 14.0.

Code:
root@molly:~ # ls -li /boot/loader*.efi
539153 -r-xr-xr-x  2 root  wheel  887808 Nov  2 22:15 /boot/loader.efi
539416 -r-xr-xr-x  1 root  wheel  798720 Nov  2 22:15 /boot/loader_4th.efi
539153 -r-xr-xr-x  2 root  wheel  887808 Nov  2 22:15 /boot/loader_lua.efi
539417 -r-xr-xr-x  1 root  wheel  741376 Nov  2 22:15 /boot/loader_simp.efi
As you can tell from the inodes loader.efi is hard linked to loader_lua.efi.
 
Does your upgraded FreeBSD system have the file /boot/lua/loader.lua?
Code:
:~# ls -li /boot/loader*.efi

4977001 -r-xr-xr-x  1 root  wheel  809984 Nov  3 17:11 /boot/loader_4th.efi
4976998 -r-xr-xr-x  2 root  wheel  896000 Nov  3 17:11 /boot/loader_lua.efi
4977003 -r-xr-xr-x  1 root  wheel  750080 Nov  3 17:11 /boot/loader_simp.efi
4976998 -r-xr-xr-x  2 root  wheel  896000 Nov  3 17:11 /boot/loader.efi

Yes. It is present. That's why, I can boot into FreeBSD by manually entering currdev to point to the FreeBSD root partition, which is in my 2nd hard drive ada1.
 
At the top of the screen shot I see a Reading loader env vars from /efi/freebsd/loader.env. That's probably a rEFInd thing. Perhaps that disk1p4 is defined there?
 
At the top of the screen shot I see a Reading loader env vars from /efi/freebsd/loader.env. That's probably a rEFInd thing. Perhaps that disk1p4 is defined there?
There is no /efi/freebsd/loader.env file there. There is only loader.efi copied from /boot/ I've put in the FreeBSD folder.
This is the current boot screen. As you see, it is disk0p1 which is now (wrongly) selected as currdev.

index.jpg


Code:
:~% cat /boot/loader.conf
autoboot_delay="1"
#boot_verbose=1
fuse_load="YES"
kern.vty=vt
hw.vga.textmode=1
#kern.vt.fb.default_mode="1920x1080"
rootdev="disk1p2"
currdev="disk1p2"
coretemp_load="YES"
cpu_microcode_load="YES"
cpu_microcode_name="/boot/firmware/intel-ucode.bin"
sysctlinfo_load="YES"
sysctlbyname_improved_load="YES"
if_run_load="YES"
runfw_load="YES"
snd_hda_load="YES"
mixer_enable="YES"
sound_load="YES"
compat.linuxkpi.i915_disable_power_well="0"
sysctlinfo_load="YES"

/boot/defaults/loader.conf is untouched.
 
uefi(8)
Code:
           3.   loader.efi searches partitions of type freebsd-ufs and
                freebsd-zfs for loader.efi.  The search begins with partitions
                on the device from which loader.efi was loaded, and continues
                with other available partitions.  If both freebsd-ufs and
                freebsd-zfs partitions exist on the same device the
                freebsd-zfs partition is preferred.
That 'and continues with other available partitions' bit is a bit unclear. It doesn't appear to be looking for partitions on other disks. Which is probably why it's not finding the freebsd-ufs partitions on the second disk. That seems to be a bug.
 
Abraham79,

Please boot your freebsd system, and try adding this menuentry at the end of your
/boot/efi/EFI/refind/refind.conf file:
Code:
menuentry "FreeBSD" {
  loader /EFI/freebsd/loader.efi
  options "currdev=disk1p2"
  icon /EFI/refind/icons/os_freebsd.png
}

Hopefully it should boot. I tried this on my zfs system with
options "currdev=zfs:zroot/ROOT/default" and it worked. My freebsd-zfs partition is actually on disk0p4.

options="rootdev=zfs:zroot/ROOT/default", on the other hand, did NOT work.

I don't have a 2 disk system to test this with, so I hope it works for you too.
 
That 'and continues with other available partitions' bit is a bit unclear. It doesn't appear to be looking for partitions on other disks. Which is probably why it's not finding the freebsd-ufs partitions on the second disk. That seems to be a bug.
It was working until 12.2? This happened after the upgrade.
 
My understanding is that each disk/device is supposed to have it's own ESP. I believe the problem here is that loader.efi gets loaded from a different disk. If your second disk had it's own ESP containing loader.efi, rEFInd would probably find it there and go along with it, having the current device correctly initialized to the disk it was loaded from. Setting anything in /boot/loader.conf (or any other file contained in the root filesystem for that matter) is futile, as loader.efi doesn't find that partition in the first place. It seems that loader.efi is looking for a file /efi/freebsd/loader.env on the ESP, but it's not quite clear what could go into such file. According to the source code /usr/src/stand/efi/loader/main.c:
C:
        /*
         * Read additional environment variables from the boot device's
         * "LoaderEnv" file. Any boot loader environment variable may be set
         * there, which are subtly different than loader.conf variables. Only
         * the 'simple' ones may be set so things like foo_load="YES" won't work
         * for two reasons.  First, the parser is simplistic and doesn't grok
         * quotes.  Second, because the variables that cause an action to happen
         * are parsed by the lua, 4th or whatever code that's not yet
         * loaded. This is relative to the root directory when loader.efi is
         * loaded off the UFS root drive (when chain booted), or from the ESP
         * when directly loaded by the BIOS.
         *
         * We also read in NextLoaderEnv if it was specified. This allows next boot
         * functionality to be implemented and to override anything in LoaderEnv.
         */
        read_loader_env("LoaderEnv", "/efi/freebsd/loader.env", false);
        read_loader_env("NextLoaderEnv", NULL, true);
As this file resides on the ESP and not the root filesystem, I'd say it's your best bet on setting any loader environment variables.
 
It seems loader.env functions are undocumented
I had a feeling that would be the solution but couldn't find any documentation for it. It doesn't help if it's actually undocumented :(

Anyway, good to see you found a working solution.
 
Back
Top