Jakob Gillich Personal blog

Getting started with bhyve

I’ve been running a home server for a few years, but my upload is just too poor to do anything serious with it, so I got myself a cheap dedicated server. Installed FreeBSD, because lets try bhyve, their new-ish hypervisor.

The default “frontend” to bhyve is quite complex, so I used vm-bhyve instead, which can definitely compete with Docker in ease of use.

So let’s install it. It is in ports, but the package usually outdated, so make sure you install from source.

# if you don't have the ports tree yet
portsnap fetch extract
cd /usr/ports/sysutils/vm-bhyve && make install clean

If you plan to run anything other than FreeBSD, you’ll also need grub2-bhyve:

cd /usr/ports/sysutils/grub2-bhyve && make install clean

Some initial config:

mkdir /var/vm
zfs create -o mountpoint=/var/vm zroot/vm
echo 'vm_enable="YES"' >> /etc/rc.conf
echo 'vm_dir="zfs:zroot/vm"' >> /etc/rc.conf
vm init
cp /usr/local/share/examples/vm-bhyve/* /var/vm/.templates/

This is enough to be able to launch VMs, but we want networking as well.

echo 'net.inet.ip.forwarding=1' >> /etc/sysctl.conf
echo 'pf_enable="YES"' >> /etc/rc.conf
vm switch create public
vm switch add public em0
vm switch nat public on
pkg install dnsmasq
echo 'dnsmasq_enable="YES"' >> /etc/rc.conf
mv /usr/local/etc/dnsmasq.conf.bhyve /usr/local/etc/dnsmasq.conf
service dnsmasq start

vm-bhyve will add a include line to /etc/pf.conf, you might have to move it up a bit (check with pfctl -f /etc/pf.conf).

Now, we need an ISO, which vm-bhyve can download for us:

vm iso ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/10.3/FreeBSD-10.3-RELEASE-amd64-disc1.iso

If you want to download iso manually, just put them in /var/vm/.iso/. Let’s launch a VM:

vm create -t freebsd-zpool -s 50G freebsd1
vm install freebsd1 FreeBSD-10.3-RELEASE-amd64-disc1.iso
vm console freebsd1

Now, just go through the installer as usual. Easy!

Next step: figure out how to assign IPv6 addresses to VMs. Hopefully not too hard.