Skip to content

Instantly share code, notes, and snippets.

@ryanavella
Last active January 22, 2023 00:59
Show Gist options
  • Save ryanavella/f3c9ba8e74bc29870877697c95882fb5 to your computer and use it in GitHub Desktop.
Save ryanavella/f3c9ba8e74bc29870877697c95882fb5 to your computer and use it in GitHub Desktop.
My Bhyve Setup on FreeBSD

Bhyve on FreeBSD

This guide shows how I configure bhyve on FreeBSD.

vm-bhyve

First, install the vm-bhyve package. Optionally, install grub2-bhyve for Linux guests.

# pkg install vm-bhyve grub2-bhyve

Create a dataset for the virtual machines to live in.

# zfs create zroot/vm

Enable vm-bhyve and point to the dataset we just created.

# sysrc vm_enable=yes
# sysrc vm_dir=zfs:zroot/vm

Run the vm init command to create the necessary staging directories.

# vm init

Install the sample templates.

# cp /usr/local/share/examples/vm-bhyve/* /zroot/vm/.templates/

NAT

I'm still investigating how to put my VM's into a bridged configuration, but for now I use a NAT approach. This article on Roma's blog looks look a good starting point for when I do make another attempt.

I use the 10.210.0.0/16 network for my guests, and 10.210.0.1 as the gateway.

Enable the gateway and pf services.

# sysrc gateway_enable=yes
# sysrc pf_enable=yes

Create a NAT rule to relay traffic between the two networks. Replace wlan0 with your public-facing interface.

# echo "nat on wlan0 from {10.210.0.0/16} to any -> (wlan0)" >> /etc/pf.conf

Enable ip forwarding and start the pf service:

# sysctl net.inet.ip.forwarding=1
# service pf start

Create the bridge interface.

# vm switch create -a 10.210.0.1/16 public
# vm switch add public wlan0

Guest Installation

Make any desired tweaks to the template file. This is what my freebsd-zvol.conf looks like.

# cat /zroot/vm/.templates/freebsd-zvol.conf
loader="bhyveload"
cpu=4
memory=8G
network0_type="virtio-net"
network0_switch="public"
disk0_type="virtio-blk"
disk0_name="disk0"
disk0_dev="sparse-zvol"

Download a .iso for the guest.

# vm iso https://download.freebsd.org/ftp/releases/ISO-IMAGES/13.0/FreeBSD-13.0-RELEASE-amd64-bootonly.iso

Create a FreeBSD guest from the template and begin installation.

# vm create -t freebsd-zvol -s 10G fsbd-13.0-release
# vm install -f fsbd-13.0-release FreeBSD-13.0-RELEASE-amd64-bootonly.iso

References

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment