Solved how to force creation of GPT and BIOS+UEFI in modified bsdinstall script

I was trying to automatically install FreeBSD through bsdinstall and was intending to use these options:

Code:
PARTITIONS=$_CONF_DEV
DISTRIBUTIONS="kernel.txz base.txz"
export ZFSBOOT_PARTITION_SCHEME="GPT"
export ZFSBOOT_BOOT_TYPE="BIOS+UEFI"
export ZFSBOOT_POOL_NAME=z_${_CONF_DEV_NAME}
export ZFSBOOT_SWAP_ENCRYPTION=no
export ZFSBOOT_SWAP_SIZE=0
# TODO: support native ZFS encryption once available (FreeBSD 13)
export ZFSBOOT_GELI_ENCRYPTION=yes
export ZFSBOOT_DISKS=${_CONF_DEV}
export nonInteractive=YES

CONF_DEV, CONF_DEV_NAME are set by the user to things such as ada0, 1000.1.

When running the install script, everything is installed fine, but I cannot boot up using UEFI, instead a regular BIOS setup is created. Am I missing a variable name somewhere?
 
Hey.

My knowledge of ZFS is scarce, but could you please log into a Live CD and copy the contents of 'gpart show <provider>' and /etc/fstab?
 
Have a look at /usr/src/usr.sbin/bsdinstall/scripts/zfsboot
Maybe you want to use this script? Or did you use it?

Anyhow find lines there after
Code:
# Determine default boot type
 
Yes, I modified /usr/libexec/bsdinstall/script and /usr/libexec/bsdinstall/zfsboot or rather I created a new file and slightly tweaked it and then referenced that in my own bsdinstall.

/etc/fstab:
Code:
/dev/ada0p1 /boot/efi msdosfs rw 2 2

gpart show ada0:
Code:
1 efi (260M)
2 freebsd-boot (512k)
- free (492k)
3 freebsd-zfs (466G)
- free - (4.0k)

I need to dig around some more. Whenever I run the installer, it succeeds, it will also prompt me if I want to clear out the EFI entries and add a new one. I can see where that is in the code and ensure that it gets called from my script which it appears doesn't.
 
/etc/fstab:
Code:
/dev/ada0p1 /boot/efi msdosfs rw 2 2

gpart show ada0:
Code:
1 efi (260M)
2 freebsd-boot (512k)
- free (492k)
3 freebsd-zfs (466G)
- free - (4.0k)
These look okay... However,

When running the install script, everything is installed fine, but I cannot boot up using UEFI, instead a regular BIOS setup is created. Am I missing a variable name somewhere?
Wouldn't getting away with BIOS in ZFSBOOT_BOOT_TYPE work?
export ZFSBOOT_BOOT_TYPE="UEFI"
 
UEFI install or Legacy BIOS install is controlled through the BIOS. You cannot force FreeBSD to install either way.
"UEFI only" BIOS setting will get you want you want.
CSM is a compatibility mode for Legacy BIOS. Enable it if you want LegacyBIOS install.

Here is a hint I have learned.
When running LegacyBIOS bsdinstaller uses VGA colors, so it is royal blue screen.
On EFI bsdinstall uses 256 color so you will see a light blue screen during FreeBSD setup.

If you are color blind you could boot the FreeBSD Installer and use LiveCD mode.
Run- sysctl machdep.bootmethod
This will show how your BIOS is setup to boot.
 
Correction, the liveusb installer is booting via UEFI (the boot method is EFI and the boot screen is better than the legacy one), but after rebooting, the system doesn't see the installation, so I must have done something wrong in my script or configuration.

I have done a completely fresh install using the same liveusb installer, and it does properly boot up using UEFI.

Since it appears that my configuration looks right, then even though my changes to the scripts are minimal, I must have broken something that sets up UEFI.
 
efibootmgr(8) is needed write EFI boot variables of the install to the motherboard NVRAM.
That is how the motherboard recognizes the installation.

So you need to incorporate that into your script like this:
efibootmgr -a -c -l /mnt/EFI/freebsd/loader.efi -L FreeBSD-13.1
 
PARTITIONS=$_CONF_DEV
...
export ZFSBOOT_DISKS=${_CONF_DEV}
Those are environment variables with the same function, but PARTITIONS is usually used for UFS2 installation (bsdinstall(8), scriptedpart). For ZFS, ZFSBOOT_DISKS is set.

export ZFSBOOT_PARTITION_SCHEME="GPT"
Is not needed when it's ZFS, it's set by default to GPT.

export ZFSBOOT_SWAP_ENCRYPTION=no
Not needed to disable swap encryption, it's set by default to no ("", see bsdinstall(8)).

... even though my changes to the scripts are minimal, I must have broken something that sets up UEFI.
It would be easier to narrow down where the error of the installation scripts may be, if we could have a look at them.

Also, if you could tell us what the use case of the non-interactive installation is, maybe we are able to suggest some improvements.
 
efibootmgr(8) is needed write EFI boot variables of the install to the motherboard NVRAM.
That is how the motherboard recognizes the installation.
Not necessarily, UEFI can boot FreeBSD without a boot variable.

efibootmgr -a -c -l /mnt/EFI/freebsd/loader.efi -L FreeBSD-13.1
That won't work. To point the path to the loader, it must be set partition:/path/to/loader. For example, assuming ada0p1 as the ESP:
efibootmgr -a -c -l ada0p1:/efi/freebsd/loader.efi -L FreeBSD-13.1
 
Not necessarily, UEFI can boot FreeBSD without a boot variable.
I have seen exactly the symptoms described above.
FreeBSD memstick installer boots with EFI, does the installation, reboot and nothing.....
Defiantly not common but I have had it happen.

Here is another way. I install FreeBSD to NVMe in PCIe slot 1. Now I move NVMe to PCIe slot 3.
Won't boot. Have to reinstall or use efibootmgr.
I know it shouldn't be this way but it is. Maybe we blame some flakey EFI bios?
 
No, it is certainly a bug in my scripts.
 

Attachments

  • bsdinstall-bootstrap.txt
    370 bytes · Views: 66
  • script.custom.txt
    6 KB · Views: 53
  • zfsboot.custom.txt
    58.2 KB · Views: 57
That won't work. To point the path to the loader, it must be set partition:/path/to/loader.
I might be mistaken here. I've check on a VM, it's possible to set the loader path both ways. In a earlier FreeBSD version (not sure which one) I got an error when trying to set with /mnt/path/to/loader. Since then I used to set it partition:/path/to/loader.

My apologies Phishfry, what you suggested is perfectly fine.

Here an excerpt from efibootmgr -v:
Code:
 Boot0001* FreeBSD131 HD(1,GPT,4f762172-89c1-11ec-88c1-080027fd6086,0x28,0x82000)/File(\efi\freebsd\loader.efi)
                         ada0p1:/efi/freebsd/loader.efi /mnt//efi/freebsd/loader.efi

I have seen exactly the symptoms described above.
FreeBSD memstick installer boots with EFI, does the installation, reboot and nothing.....
Defiantly not common but I have had it happen.

Here is another way. I install FreeBSD to NVMe in PCIe slot 1. Now I move NVMe to PCIe slot 3.
Won't boot. Have to reinstall or use efibootmgr.
I know it shouldn't be this way but it is. Maybe we blame some flakey EFI bios?
Flakey UEFI could be the case. I have a a 2020 laptop (the only bare metal with UEFI I have at the moment) with two PCIe slots, switched the NVMe from one slot to the other recently but haven't experienced a non-bootable system.

I apologies tOsYZYny, deviating here from your topic.
 
Ah, yes, I think you're right. I just pulled in those changes in the patch. My script was copied from R13.0 and that would explain it. I compared the diff and that is what stood out.

I'll report back once done.

Thanks Phishfry
 
Back
Top