I have previously described how to create a virtual machine using bhyve. There is, however, a nice utility that allows for a level of simplification. It is called vm-bhyve.
In this case i will get into installing ubuntu 16.4 LTS as a virtual machine, with 16GB of ram and a 500GB drive.
Installation
The installation if vm-bhyve is pretty straight forward:
# pkg install vm-bhyve grub2-bhyve uefi-edk2-bhyve
After packages installation we will create a zfs volume specifically to be used by virtual machines.
# zfs create storage/vm
I already had a zpool that i called storage, so i’m adding a ‘vm’ volume. Here I’m not getting into how to create zpools, I have written about zfs already.
Then we will add a few entries to the /etc/rc.conf file or /etc/rc.conf.local depending how you have configured things.
vm_enable="YES"
vm_dir="zfs:storage/vm"
We then run the init command
# vm init
We now copy templates and examples:
# cp /usr/local/share/examples/vm-bhyve/* /usr/vm/.templates/
Then create a ‘public’ switch that will be used for the virtual machines
# vm switch create public
# vm switch add public bge0
Note that ‘bge0’ is the public network of my server, yours might be named differently, em0 and igb0 are common ones.
I now will copy a few installer iso files to the /usr/vm/.iso/ directory, including ubuntu-16.04.7-server-amd64.iso which i will use shortly.
I want to create a virtual machine with 16GB of ram and 500GB drive and i will call it vulpecula.
# vm create vulpecula
# zfs create -sV 500G -o volmode=dev storage/vm/andromeda/disk0
With these two commands I have first generated a new “generic” vm and second created a zfs volume for it. The first command had created a disk0.img file but i prefer to use a zfs volume.
Next I need to edit the vm configuration file:
# vi /usr/vm/vulpecula/vulpecula.conf
I’ll change it to look like this:
loader="grub"
cpu=2
memory=16G
network0_type="virtio-net"
network0_switch="public"
disk0_type="virtio-blk"
disk0_name="disk0"
disk0_dev="sparse-zvol"
uuid="don't change this"
network0_mac="don't change this"
Basically i have changed the loader, and modified the disk0_* values to use the newly created volume.