ZFS data sets as storage location for virtual machines

Using ZFS datasets offer the possibility to use functions and properties of ZFS like quotas, compression, block sizes or snapshots for VM applications.

The following call creates a file system as location for the virtual machine samplevm and mounts the file system in the directory structure at /vms/samplevm:

doas zfs create -o mountpoint=/vms/samplevm zroot/samplevm

The file system can now be used to back up files for virtual drives, EFI variables, or other VM-related data.

Backup points from virtual hard disks via ZFS snapshots

ZFS snapshots can be applied to ZFS datasets to create backup points of virtual machines (see also: ZFS volumes as data memory for virtual hard disks). The state of a virtual machine can thus be backed up at a specific point in time and restored if necessary.

A snapshot of the ZFS dataset zroot/samplevm can be created via zfs-snapshot(8):

doas zfs snapshot zroot/samplevm@latest

@latest defines the name of the snapshot.

To restore the ZFS dataset and the files stored in it to the state of the snapshot @latest, the following command can be used

doas zfs rollback zroot/samplevm@latest

During the build and restore process, the VM instance should be shut down.

More detailed information about the Z file system and the use of ZFS datasets and snapshots can be found in the chapter The Z file system in the FreeBSD documentation