ZFS volumes as data memory for virtual hard disks

ZFS volumes are a type of ZFS data sets and are listed as block devices at /dev/zvol/zroot. A ZFS volume can be used as data memory for virtual drives in order to take advantage of ZFS data sets such as snapshots, clones or compression.

The following command creates the ZFS volume zroot/vms/samplevm/disk0 in the ZFS pool zroot with 20 GB

doas zfs create -V 20G zroot/vms/samplevm/disk0

The following call starts the samplevm virtual machine with an emulated NVME hard disk that uses the ZFS volume zroot/vms/samplevm/disk0 as data storage, which is available under the directory /dev/zvol/zroot/vms/samplevm/disk0.

doas bhyve \
-c sockets=1,cores=1,threads=1 \
-m 2G \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_BHF_UEFI.fd \
-s 0,hostbridge \
-s 2,fbuf,rfb=0.0.0.0:5900,w=1024,h=768 \
-s 3,xhci,tablet \
-s 10,nvme,/dev/zvol/zroot/vms/samplevm/disk0 \
-s 31,lpc \
-A -H -P \
samplevm