back to the beginning

FreeBSD 12.0 Virtual Machines

Last updated: 2019-02-24

Virtual Machines: VirtualBox, bhyve, Jails

I wanted an Ubuntu virtual machine in order to run software that could not be run in FreeBSD properly (e.g. Spotify). VirtualBox has its own screen interface for the running virtual machine, whereas bhyve relies on using VNC to connect to the guest. Note that I was unable to get sound to work with either of them so used spotifyd for that.

With VirtualBox, you can save the state of the virtual machine from the menu, but I don't know about doing that in bhyve yet.

If switching between VirtualBox and bhyve, you need to remove the bhyve kernel module (kldunload vmm) or VirtualBox will complain. You cannot run a bhyve and a VirtualBox virtual machine at the same time.

VirtualBox

The FreeBSD Handbook on VirtualBox has everything you need to know to install and use this.

bhyve

The FreeBSD Handbook on bhyve has everything you need to know to install and use this.

See also the FreeBSD wiki bhyve

I use a zfs zvol for the virtual machine's drive:

zfs create -V20G -o volmode=dev datapool/vms/ubuntu-media-bhyve-vm

I use a script to boot the machine for installation:

bhyve -c 2 -m 4G -w -H \
-s 0,hostbridge \
-s 3,ahci-cd,/zdatapool/vms/iso/ubuntu-18.04.1-desktop-amd64.iso \
-s 4,virtio-blk,/dev/zvol/datapool/vms/ubuntu-media-bhyve-vm \
-s 5,virtio-net,tap0 \
-s 29,fbuf,tcp=0.0.0.0:5900,w=800,h=600,wait \
-s 30,xhci,tablet \
-s 31,lpc -l com1,stdio \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
vm0

bhyvectl --destroy --vm=vm0

I use a second script to run the machine:

bhyve -c 1 -m 2G -w -H \
-s 0,hostbridge \
-s 4,virtio-blk,/dev/zvol/datapool/vms/ubuntu-media-bhyve-vm \
-s 5,virtio-net,tap0 \
-s 29,fbuf,tcp=0.0.0.0:5900,w=1024,h=768,wait \
-s 30,xhci,tablet \
-s 31,lpc -l com1,stdio \
-l bootrom,/usr/local/share/uefi-firmware/BHYVE_UEFI.fd \
vm0

bhyvectl --destroy --vm=vm0

# if sound worked, adding this above would turn it on
# -s 6,hda,play=/dev/dsp0

FreeBSD Jails

  • FreeBSD Handbook Jails
  • I haven't tried these yet.

    back to the beginning

    Something need fixing? Contact me: