Install bootloader grub2.

# pkg ins grub2-bhyve

Create folder for iso-images.

# mkdir -p /vm/iso

Create folder for virtual machines.

# mkdir /vm/u3

Add modules.

# vi /boot/loader.conf

vmm_load="YES"
if_bridge_load="YES"
if_tap_load="YES"

Add autostart tap interface.

# echo 'net.link.tap.up_on_open=1' >> /etc/sysctl.conf

Create interfaces in rc.conf file.

# vi /etc/rc.conf

cloned_interfaces="bridge0 tap1"
ifconfig_bridge0="addm tap1 addm re0 up"

Go to directory with VM.

# cd /vm/u3

Create image.

# truncate -s 8G u3.img

Create setup file.

# vi device.map

(hd0) /vm/u3/u3.img
(cd0) /vm/iso/ubuntu_x64.iso

Reboot server.

# reboot

After rebooting begin install.

# grub-bhyve -r cd0 -m /vm/u3/device.map -M 512 u3
# bhyve -c 1 -m 512 -H -P -A \
-l com1,stdio \
-s 0:0,hostbridge \
-s 1:0,lpc \
-s 2:0,virtio-net,tap1 \
-s 3,ahci-cd,/vm/iso/ubuntu_x64.iso \
-s 4,virtio-blk,/vm/u3/u3.img u3

Continue installing.

After installing destroy VM process.

# bhyvectl --destroy --vm=u3

Go to VM's directory and create startup file.

# cd /vm/u3
# vi start.sh

#!/bin/sh
while [ 1 ] ; do
bhyvectl --destroy --vm=u3
grub-bhyve -r hd0,msdos1 -m /vm/u3/device.map -M 512 u3

bhyve -c 1 -m 512 -H -P -A \
-l com1,stdio \
-s 0:0,hostbridge \
-s 1:0,lpc \
-s 2:0,virtio-net,tap1 \
-s 4,virtio-blk,/vm/u3/u3.img u3
bhyve_exit=$?
if [ $bhyve_exit -ne 0 ]; then
break
fi
done
bhyvectl --destroy --vm=u3

Write and quit.

Give rights to execute and run script.

# chmod +x start.sh
# ./start.sh