Virtual drives
Virtual machines can be configured with virtual drives (block storage devices). These can in turn be used as virtual hard disks (nvme, ahci-hd or virtio-blk) or as a virtual CD-ROM drive (ahci-cd).
The following call starts the virtual machine samplevm
with an emulated NVMe drive and a virtual AHCI CD-ROM drive:
doas bhyve \
-c sockets=1,cores=2,threads=1 \
-m 2G \
-l bootrom,/vms/samplevm/BHYVE_BHF_UEFI.fd,/vms/samplevm/EFI_VARS.fd,fwcfg=qemu \
-s 0,hostbridge \
-s 2,fbuf,rfb=0.0.0.0:5900,w=1024,h=768 \
-s 3,xhci,tablet \
-s 10,nvme,/vms/samplevm/disk0.img \
-s 15,ahci-cd,/vms/samplevm/os-installer.iso,ro \
-s 31,lpc \
-H -P -A \
samplevm
The resulting VM configuration looks as follows:
Both drives use regular files as disk image or ISO-CDROM on the TwinCAT/BSD host as data memory. Both files must exist before bhyve is called. Alternatively, block devices such as ZFS volumes can also be transferred as data memory (see: ZFS volumes as data memory for virtual hard disks).
To make the configured drives known to guest operating systems via ACPI, the parameter -A
must also be passed.
In the sample above, the disk image file /vms/samplevm/disk0.img
is used as data memory for the virtual hard disk (see: Disk image files as data memory for virtual hard disks).
The file /vms/samplevm/os-installer.iso
is only accessed for reading. If the memory image of os-installater.iso
corresponds to a bootable ISO image, the installation of an operating system can be started within the virtual machine, for example (see: Installing Debian Linux as a guest operating system).
In this sample, both files are stored in the directory /vms/samplevm, which belongs to the previously created ZFS dataset zroot/samplevm. The ZFS dataset therefore serves as a storage location for the persistent data of the virtual machine. This means that ZFS snapshots can be used to back up and restore data.