Getting started with bhyve

May 13, 2016

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 so I could try bhyve, their new-ish hypervisor.

The default "frontend" to bhyve is quite complex, so I used vm-bhyve instead, which is similar to Docker in ease of use.

Let's install it. The package is often outdated, so I prefer installation 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 an 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

If you want to download ISO's manually, 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!

Back to blog