There are various benefits to using a ZFS backed block storage device, or ZVOL, as opposed to large file on disk. In this article I look at how virtual machines can be made using ZFS backed block storage, as opposed to regular Virtualbox files.
When creating a regular file to back a virtual machine, whenever a change has been made to that large file, a new copy must be made and stored whenever it is snapshotted. Using a ZVOL means the storage for the VM can be kept outside of regular datasets, and thus excluded from unneccesary snapshots. In addition to this, it is also possible to use ZFS snapshots instead of Virtualbox snapshots. While this does have some pitfalls, including the fact that if a snapshot is made while the VM is currently running the consistency of the file system could be in jeopardy; however, as long as snapshots are only made while the VM is off there shouldn’t be a problem.
Create a ZVOL
Create a 25GB VM called
Now the problem is accessing the ZVOL as a regular user. In order to create a disk in Virtualbox as an unprivledged user, set the owner and group.
For the short-term, using
chown to obtain ownership of the ZVOL works, but once the computer has been restarted, ownership will be lost. In order to make it permenant, add a udev rule for the ZVOL, by creating a new file
/etc/udev/rules.d/ that contains the following:
This will make the ZVOL at
tank/zvol-archlinux owned by user john, in group disk, and with permissions
After applying the new rule, refresh the rules with
udevadm control --reload.
Create The Disk
Now create the “wrapper” disk for Virtualbox. Specify a location for the resulting Virtualbox file, and the ZVOL being used.
It should say:
This will create a new file “archlinux.vmdk” that is backed by the ZVOL.