Run FreeBSD as virtual machine using bhyveD

I wanted to experiment with the then upcoming FreeBSD 15 and decided to install it as virtual machine with bhyve on an already running bare-metal install of FreeBSD 14.2. I grabbed the latest FreeBSD-15.0-ALPHA3-amd64-ufs.raw.xz disk image and uncompressed it:

# fetch https://download.freebsd.org/snapshots/VM-IMAGES/15.0-ALPHA3/amd64/Latest/FreeBSD-15.0-ALPHA3-amd64-ufs.raw.xz
# unxz FreeBSD-15.0-ALPHA3-amd64-ufs.raw.xz
Then, I created this shell script to boot the virtual machine:
# cat >>vmrun15.sh <<EOF
#!/bin/sh

echo "Start in another terminal: cu -l /dev/nmdm0A"
kldload -n nmdm
bhyveload -c /dev/nmdm0B -d /root/FreeBSD-15.0-ALPHA3-amd64-ufs.raw -m 1280M -e autoboot_delay=3 fbsd15
ifconfig tap0 create
ifconfig bridge0 addm tap0
bhyve -A -H -P -c 2 -m 1280M -s 0:0,amd_hostbridge -s 1:0,lpc -s 2:0,virtio-blk,/root/FreeBSD-15.0-ALPHA3-amd64-ufs.raw -s 3:0,virtio-net,tap0 -l com1,/dev/nmdm0B fbsd15
ifconfig bridge0 deletem tap0
ifconfig tap0 destroy
bhyvectl --destroy --vm=fbsd15
EOF
The network interface bridge0 pre-existed on the host and comprises two physical ethernet LAN ports.
Finally, I made that script executable and started the virtual machine:
# chmod 0755 vmrun15.sh
# ./vmrun15.sh
Connect to the virtual serial console using the shown command cu -l /dev/nmdm0A, login to the guest, and set a root password.

Resize virtual disk

As the provided disk image is quite small, you might want to increase it. First, shutdown the virtual machine:

# shutdown -p now
Then, on the physical host, resize the disk image:
# truncate -s 20G FreeBSD-15.0-ALPHA3-amd64-ufs.raw
Edit the vmrun15.sh script and instruct bhyveload to boot into single user mode:
bhyveload -c /dev/nmdm0B -d /root/FreeBSD-15.0-ALPHA3-amd64-ufs.raw -m 1280M -e autoboot_delay=3 -e boot_single=YES fbsd15
Now, start vmrun15.sh and connect to the serial console again. Simply press enter when asked which shell you want to use:
Trying to mount root from ufs:/dev/gpt/rootfs [rw]...
Enter full pathname of shell or RETURN for /bin/sh: 
root@:/ # 
Refresh the disk's size, and then resize the last partition to the maximum size:
# gpart recover vtbd0
# gpart resize -i 4 vtbd0
Check the filesystem before you resize it:
# fsck /dev/vtbd0p4
# growfs /dev/vtbd0p4
Now boot into multi-user mode:
# exit
Edit vmrun15.sh and remove the option -e boot_single=YES again to avoid booting into single user mode next time.

VNC

In case you prefer a graphical console that you can connect to over the network, switch to VNC. Unfortunatelly, this requires the UEFI mode of bhyve for which you have to install the required firmware first:

# pkg install bhyve-firmware
Then, edit vmrun15.sh, comment out bhyveload, and give VNC a higher precedence than the serial console, i.e. assign a lower virtual PCI slot to the framebuffer device than the serial console:
#bhyveload -c /dev/nmdm0B -d /root/FreeBSD-15.0-ALPHA3-amd64-ufs.raw -m 1280M -e autoboot_delay=3 fbsd15
...
bhyve -A -H -P -c 2 -m 1280M -s 0:0,amd_hostbridge -s 4:0,lpc -s 2:0,virtio-blk,/root/FreeBSD-15.0-ALPHA3-amd64-ufs.raw -s 3:0,virtio-net,tap0 -l com1,/dev/nmdm0B -s 1:0,fbuf,rfb=0.0.0.0:5900 -l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd fbsd15
You might want to restrict access to VNC to your local network only. Thus, either replace 0.0.0.0 with you physical host's LAN ip address, or set up some firewall rules.