This is an old revision of the document!


Install a FreeBSD VM is relatively easier now in a FreeBSD host via the bhyve hypervisor. The following is my simple list of actions to create a new FreeBSD 13 VM. My FreeBSD host (running 13.2-RELEASE-p4) is called n1.

cc@n1:/ % sudo pkg install vm-bhyve                     // simple vm(8) management
cc@n1:/ % sudo zfs create zroot/bhyve                   // parent data pool for VMs 
cc@n1:/ % sudo zfs create zroot/bhyve/.templates        // used to store VM configs
Find the pci device (WiFi 6 wireless interface) on host to pass through the VM. The bus/slot/function is for this devices is 2/0/0.
cc@n1:~ % sudo pciconf -lv
...
iwlwifi0@pci0:2:0:0:	class=0x028000 rev=0x1a hdr=0x00 vendor=0x8086 device=0x2723 subvendor=0x8086 subdevice=0x0084
    vendor     = 'Intel Corporation'
    device     = 'Wi-Fi 6 AX200'
    class      = network
...
vmm_load="YES"
nmdm_load="YES"
if_bridge_load="YES"
if_tap_load="YES"
# the passthru pci device
pptdevs="2/0/0"
# default AMD-Vi passthrough support is disabled, enable it
hw.vmm.amdvi.enable="1"
net.link.tap.up_on_open=1
# needed for virtualization support 
vm_enable="YES"
vm_dir="zfs:zroot/bhyve"
This file is used as the config file for a new FreeBSD VM.
cc@n1:~ % cat /zroot/bhyve/.templates/fbsd.conf 
loader="bhyveload"

cpu=4 
cpu_sockets=1 
cpu_cores=4

memory=4G 

# put up to 8 disks on a single ahci controller. This avoids the creation of 
# a new “controller” on a new “PCIe slot” for each drive added to the guest. 
ahci_device_limit="8"

# e1000 works out-of-the-box, but virtio-net performs better. Virtio support 
# is built in on FreeBSD and Linux guests, but Windows guests will need 
# to have virtio drivers manually installed. 

#network0_type="e1000"
network0_type="virtio-net"
network0_switch="public"

# bhyve/nvme storage is considerably faster than bhyve/virtio-blk storage.
#disk0_type="virtio-blk"
disk0_type="nvme"
disk0_name="disk0"
disk0_dev="sparse-zvol"

# This gives the guest a virtual "optical" drive. Specifying disk1_dev=”custom” 
# allows us to provide a full path to the ISO. 

disk1_type="ahci-cd" 
disk1_dev="custom" 
disk1_name="/zroot/bhyve/FreeBSD-13.2-RELEASE-amd64-disc1.iso"

# passing of host PCI devices to a virtual machine for its exclusive use of them
passthru0="2/0/0"
cc@n1:/zroot/bhyve % sudo vm init
cc@n1:/zroot/bhyve % ifconfig | grep RUNNING
re0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
cc@n1:/zroot/bhyve % sudo vm switch create public
cc@n1:/zroot/bhyve % sudo vm switch add public re0
cc@n1:/zroot/bhyve % sudo vm create -t fbsd -s 100G n1_iwl_vm
cc@n1:/zroot/bhyve % sudo vm install n1_iwl_vm ./FreeBSD-13.2-RELEASE-amd64-disc1.iso
Starting n1_iwl_vm
  * found guest in /zroot/bhyve/n1_iwl_vm
  * booting...
Use the "vm console" command to access the VM and finish the installation process.
cc@n1:~ % sudo vm console n1_iwl_vm
  • chengcui/install_freebsd13_vm_via_bhyve.1699390300.txt.gz
  • Last modified: 2023/11/07 20:51
  • by chengcui