Install Ubuntu on FreeBSD with byhve

published on on FreeBSD, bhyve, Ubuntu

For some reasons I needed a Linux installation on my NAS. byhve is a lightweight virtualization solution for FreeBSD that makes that easy and efficient. However, the CLI of bhyve is somewhat bulky and bare making it hard to use, especially for the first time. This is what vm-bhyve solves - it provides a simple CLI for working with virtual machines.

The only requirement seems to be VT-x CPU support or whatever it may be called on AMD CPUs and ZFS as a file system. I run it on FreeBSD 11.

I think anyone interested in this topic has enough experience to know what this is about from reading the commands below, so I will save a more detailed explanation rather than showing you how I did it.

So here's how to install Ubuntu 16.04 as a guest OS on FreeBSD using bhyve:

# Install required packages
pkg install vm-bhyve grub2-bhyve

# Load kernel modules
kldload if_bridge if_tap nmdm vmm

# Make loading of kernel modules persistent
echo 'if_bridge_load="YES"' >> /boot/loader.conf
echo 'if_tap_load="YES"' >> /boot/loader.conf
echo 'nmdm_load="YES"' >> /boot/loader.conf
echo 'vmm_load="YES"' >> /boot/loader.conf

# Set configuration for byhve-vm
sysrc vm_enable="YES"
sysrc vm_dir="zfs:zroot/vms"
sysrc vm_list=""
sysrc vm_delay="5"

# Create filesystem for VMs
zfs create -o mountpoint=/vms zroot/vms
vm init
cp /usr/local/share/examples/vm-bhyve/* /vms/.templates/

# Create bridge device, replace em0 with your network controller
vm switch create public
vm switch add public em0

# Grab Ubuntu 16.04 ISO
vm iso

# Create VM and start installation from the ISO. After installation is done
# and OpenSSH is configured to start on boot, shut down the machine to gain back
# control over your FreeBSD session
vm create -t ubuntu -s 100G myubuntu
vm install myubuntu ubuntu-16.04.2-server-amd64.iso

# Enable autostart of the newly created VM
sysrc vm_list="myubuntu"

# Optional, give it more resources or whatsoever
vm configure myubuntu

# Start VM
vm start myubuntu

# Open console on VM
vm console myubuntu