debian vm with bhyve

bhyve(8) is a hypervisor available on FreeBSD. I personally use vm-bhyve(8) to manage my virtual machines because I find it a bit easier.

pkg install vm-bhyve
pkg install bhyve-firmware

First of all I need dataset for virtual machines (if ZFS is being used).

zfs create zroot/bhyve

Then update my system configuration (rc.conf(5)).

sysrc vm_enable="YES"
sysrc vm_dir="zfs:zroot/bhyve"

I run vm init to finish initialisation. This will create subdirectories inside the dataset.

vm init

To enable network for the VMs I create virtual switch and attach my network interface to it.

iconfig
vm switch create public
vm switch add public re0
ifconfig

Now I'm ready to create Debian's VM. There should be a sample config for this already.

cp /usr/local/share/examples/vm-bhyve/debian.conf /zroot/bhyve/.templates/

In my case I want to use debian template (-t) and specify disk image size (-s) to be 40G. The following command will create directory with config, disk image and log. This is also a good moment to edit VM's config file and set things like RAM.

vm create -t debian -s 40G debian_vm

VM is now created but nothing is yet installed on it. I need installation image, it can be downloaded with vm iso (it will be placed inside /zroot/bhyve/.iso/).

vm iso https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/debian-12.9.0-amd64-DVD-1.iso

Now I can install Debian on my new VM.

vm install -f debian_vm debian-12.9.0-amd64-DVD-1.iso

I don't use -f if I plan to connect via VNC. Otherwise guest will be started in in the foreground on stdio.

After the installation VM is ready to be used.

vm start debian_vm
vm console debian_vm

vm(8) uses cu(1), to exit console back to the host use ~^D or ~.~.

GUI is available via VNC (works only with uefi). There should be sample configs available.

egrep "^graphics" -R /usr/local/share/examples/vm-bhyve/