bhyve How to use BHYVE_UEFI_VARS.fd?

Hi,

Could someone please help explain or point to any notes regarding how to use BHYVE_UEFI_VARS.fd? I've been searching around but couldn't find any yet.

TIA,
 
A varfile is provided, that file is also mapped in the boot firmware guest
address space, and any modifications the guest makes will be saved
to that file.


So basically the var file holds UEFI variables settings for your VM.

Variable services UEFI variables provide a way to store data, in particular non-volatile data. Some UEFI variables are shared between platform firmware and operating systems. Variable namespaces are identified by GUIDs, and variables are key/value pairs. For example, UEFI variables can be used to keep crash messages in NVRAM after a crash for the operating system to retrieve after a reboot.[46]
 

So basically the var file holds UEFI BIOS settings for your VM.
I might miss but I couldn't see:
* Where to put the varfile, inside or outside VM?
* How to let boot manager know which varfile to use (through bhyve parameter? (which I can't find in the documentation)
* What content should be in that varfile?
 
You need to copy an empty BHYVE_UEFI_VARS.fd for each VM you create. This file should only be used by individual virtual machine. Perhaps some wrappers can do this automatically, for example, CBSD uses a personal directory per VM to store various information, including UEFI_VARS ( an empty BHYVE_UEFI_VARS.fd file is included in the CBSD package ):

Code:
env LIB9P_LOGGING=/usr/jails/jails-system/freebsd1/cbsd_lib9p.log \
/usr/bin/nice -n 1 /usr/sbin/bhyve -c 1 -m 1073741824 -H \
-A -U 8db85df2-884c-11ec-9195-6805caa77617 -s 0,hostbridge \
-s 4,virtio-blk,/usr/jails/vm/freebsd1/dsk1.vhd,sectorsize=512/4096 \
-s 5,ahci-cd,/usr/jails/jails-system/freebsd1/seed.iso,ro \
-s 6,virtio-net,tap2,mtu=1500,mac=00:a0:98:ba:7f:05 \
-s 7,virtio-rnd -s 8,fbuf,tcp=127.0.0.1:5900,w=1024,h=768,password=cbsd \
-s 30,xhci,tablet -s 31,lpc -l com1,stdio \
-l bootrom,/usr/local/cbsd/upgrade/patch/efi.fd,/usr/jails/jails-system/freebsd1/BHYVE_UEFI_VARS.fd freebsd1

Where /usr/jails/jails-system/freebsd1 - CBSD specific directories for VM settings/VARS
 
You need to copy an empty BHYVE_UEFI_VARS.fd for each VM you create. This file should only be used by individual virtual machine. Perhaps some wrappers can do this automatically, for example, CBSD uses a personal directory per VM to store various information, including UEFI_VARS ( an empty BHYVE_UEFI_VARS.fd file is included in the CBSD package ):

Code:
env LIB9P_LOGGING=/usr/jails/jails-system/freebsd1/cbsd_lib9p.log \
/usr/bin/nice -n 1 /usr/sbin/bhyve -c 1 -m 1073741824 -H \
-A -U 8db85df2-884c-11ec-9195-6805caa77617 -s 0,hostbridge \
-s 4,virtio-blk,/usr/jails/vm/freebsd1/dsk1.vhd,sectorsize=512/4096 \
-s 5,ahci-cd,/usr/jails/jails-system/freebsd1/seed.iso,ro \
-s 6,virtio-net,tap2,mtu=1500,mac=00:a0:98:ba:7f:05 \
-s 7,virtio-rnd -s 8,fbuf,tcp=127.0.0.1:5900,w=1024,h=768,password=cbsd \
-s 30,xhci,tablet -s 31,lpc -l com1,stdio \
-l bootrom,/usr/local/cbsd/upgrade/patch/efi.fd,/usr/jails/jails-system/freebsd1/BHYVE_UEFI_VARS.fd freebsd1

Where /usr/jails/jails-system/freebsd1 - CBSD specific directories for VM settings/VARS
Appreciate the input. I'm quite confused though, I thought BHYVE_UEFI_VARS.fd is the firmware that supports varfile and it can't be empty. Isn't that correct?
My configuration is either (assuming I have only 1 VM):
Code:
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd
or (this doesn't work):
Code:
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_VARS.fd

Compared to your input, I might have misunderstood BHYVE_UEIF_VARS.fd completely.
 
BHYVE_UEFI_VARS.fd used as database for non-volatile variable store. So yes, in your case you don't use it. For example, this file can store information about the correct boot device:

1644518236861.png


There are many users reports when after installing the OS in bhyve, the virtual machine cannot boot. I don't know how others have solved this, but for the last 7 years I've been using reFIND (still default firmware for CBSD) to get around this problem. Now life is easier.
 
> /usr/local/share/uefi-firmware/BHYVE_UEFI_VARS.fd

This file cannot be shared between virtual machines! Otherwise, each operating system will leave entries in it that will interfere with others. Create a script that will always copy this file for a new VM to a unique location
 
BHYVE_UEFI_VARS.fd used as database for non-volatile variable store. So yes, in your case you don't use it. For example, this file can store information about the correct boot device:

View attachment 12938

There are many users reports when after installing the OS in bhyve, the virtual machine cannot boot. I don't know how others have solved this, but for the last 7 years I've been using reFIND (still default firmware for CBSD) to get around this problem. Now life is easier.

That clarifies a lot of things. Thanks and yes, I have no problem having different BHYVE_UEFI_VARS.fd for different VM. Do you know how I could generate that file (syntax, tool...)? Sorry for continuous questions but I couldn't find any (could be my search keyword but I did try multiple variations).

To be clear, I'm trying with minimum tools involved possible for now. I'll for sure check out reFIND.
 
That clarifies a lot of things. Thanks and yes, I have no problem having different BHYVE_UEFI_VARS.fd for different VM. Do you know how I could generate that file (syntax, tool...)? Sorry for continuous questions but I couldn't find any (could be my search keyword but I did try multiple variations).
Looks like there should be a template file somewhere:
"Be sure to create a per-guest copy of the template VARS file from"

EDIT: Are you running -CURRENT? This commit hasn't landed in 13-STABLE yet.
 
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd
I really dislike these long paths. For bhyve I make a seperate gmirror and mount it at /VM
I put the UEFI firmware and the VM Images in this directory.
If I was using a var file I would put it in there too.
Short paths just make life so much easier.
 
Empty files are created with truncate(1).

The file name is irrelevant since you need to declare it in the -l options.
That is how you can use multiple var files in the same directory.
Just name them different.

Yup even that spelling would work.
If it's just empty file, why would one need it though? I thought I could use that file to pass some booting variables (hence varfile)?
 
I really don't think this is live on 13-RELEASE guys. That's probably why trying to specify a VARS file just doesn't work.
 
That's right, it was not included in the 13.0-RELEASE, but this line is still incorrect:

-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_VARS.fd

There's a chance we'll see this in the upcoming 13.1-RELEASE ( MFC After: 1 week ), but for now it's only available in the FreeBSD 14-CURRENT.

Also, I doubt that it is enough to create a file through truncate: when I wrote that need to use an empty file, I meant - take the original file that comes with the UEFI firmware build - this file has a certain structure.
 
Also, I doubt that it is enough to create a file through truncate: when I wrote that need to use an empty file, I meant - take the original file that comes with the UEFI firmware build - this file has a certain structure.
C is not my first language. Keep that in mind.

If I'm reading this diff correctly, the "ROM" loader expects a list of exactly two files, separated by a comma. The first file is opened read-only and is read into the guest's "ROM" memory. The second file is opened read-write and is mapped into the guest's "ROM" address space.

EDIT: This is wrong. See below.
If that analysis is correct, you should create a vars file by copying /usr/local/share/uefi-firmware/BHYVE_UEFI.fd somewhere. The name doesn't matter. So something like

Again, I'm pretty sure this will only work on 14-CURRENT.
 
From what I understood by reading the code (could be wrong though):

BHYVE_UEFI.fd should be used when there's no need for boot vars, for example:
Code:
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd

BHYVE_UEFI_VARS should be used when there's a need for boot vars, for example:
Code:
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_VARS.fd,/path/to/var/file
/path/to/var/file is the file used to pass boot vars, but I'm not clear on what the content/template would be.

I'll wait a bit for 13.1-RELEASE to revisit. Hopefully by then we have more documentation about it and will resolve by then as appropriate. Thanks everyone for your input.
 
From what I understood by reading the code (could be wrong though):

BHYVE_UEFI.fd should be used when there's no need for boot vars, for example:
Code:
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd

BHYVE_UEFI_VARS should be used when there's a need for boot vars, for example:
Code:
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI_VARS.fd,/path/to/var/file
/path/to/var/file is the file used to pass boot vars, but I'm not clear on what the content/template would be.

I'll wait a bit for 13.1-RELEASE to revisit. Hopefully by then we have more documentation about it and will resolve by then as appropriate. Thanks everyone for your input.
You're right. The bootrom string specifies the device being configured, not a file name. Right now a single file name is processed.
 
BHYVE_UEFI.fd should be used when there's no need for boot vars, for example:

BHYVE_UEFI_VARS should be used when there's a need for boot vars, for example:
I don't think this is right.
BHYVE_UEFI.fd is the Intel Tiano EDK2 UEFI Firmware. It is required for all EFI VM's.

BHYVE_UEFI_VARS.fd would supplement the firmware.
It gives the BIOS Firmware somewhere to save settings.

So the setting would be just as Ole showed:
-l bootrom,/usr/local/cbsd/upgrade/patch/efi.fd,/usr/jails/jails-system/freebsd1/BHYVE_UEFI_VARS.fd freebsd1
efi.fd being his renamed firmware (Which I know can be renamed to whatever you want)
BHYVE_UEFI_VARS.fd being the "data store" for the firmware. (Betting this could be custom name too)

See what I mean about long paths? It makes stuff hard to read.
 
Do you know how I could generate that file (syntax, tool...)?
My revised answer is build the port. The template file is included.
PLIST_FILES= ${PREFIX}/share/uefi-firmware/BHYVE_UEFI.fd \
${PREFIX}/share/uefi-firmware/BHYVE_UEFI_CODE.fd \
${PREFIX}/share/uefi-firmware/BHYVE_UEFI_VARS.fd

sysutils/uefi-edk2-bhyve/

The var file could also be installed with pkg install uefi-edk2-bhyve
It is installed in /usr/local/share/uefi-firmware/.
 
Back
Top