FreeBSD bhyve VM on ZFS - 2023-08-06
The default disk type when using vm-bhyve is a file on the filesystem. Changing it to ZFS is quite easy.
Setup
Assuming the following configuration after installing vm-bhyve in /etc/rc.conf
:
vm_enable="YES"
vm_dir="zfs:zroot/vms"
And a vm-bhyve mountpoint set to /usr/local/vms
.
Howto
First we create a new VM. In this guide we use the name testvm
.
vm create -t alpine -c 1 -m 2G testvm
Meaning:-t alpine
: use the alpine template-c 1
: one core-m 2G
: 2GB of memory
Delete the disk image file as we will not need it.
rm /usr/local/vms/testvm/disk0.img
Create a ZFS dataset underneath the dataset used for the VM:
zfs create -V20G -o volmode=dev zroot/testvm/disk0
Meaning:-V20G
: Create dataset with a size of 20GBdisk0
: Name of the dataset which needs to be referenced in the configuration
file
Alter the configuration in /usr/local/vms/testvm/testvm.conf
to look like
this:
loader="uefi"
cpu="1"
memory="2G"
network0_type="virtio-net"
network0_switch="public"
disk0_type="nvme"
disk0_dev="zvol"
disk0_name="disk0"
This is it. Now you can start installing an OS as you would normally do via vm install testvm <iso>
.
If you plan on installing your OS via a GUI, you might want to add the following to you configuration to be able to connect via VNC to your VM (requires UEFI!):
xhci_mouse="yes"
graphics="yes"
graphics_res="800x600"