FreeBSD: How To Run Ubuntu (Or Any Distro) With vm-bhyve

Written by: Donovan / Last updated: Oct 10, 2022

Want to run Ubuntu or another Linux distro virtualized in FreeBSD?

What if I told you that VirtualBox isn’t needed for this?

This quick guide will run you through the necessary steps to quickly setup bhyve using vm-bhyve.

FreeBSD: vm-bhyve steps for installing Ubuntu

Installation steps

Here are the installation steps I used in order:

1. doas pkg install vm-bhyve (optional: grub2-bhyve)
2. kldload if_bridge if_tap nmdm vmm
3. doas sysrc vm_enable="YES"
4. doas sysrc vm_dir="zfs:zroot/vms"
5. doas zfs create -o mountpoint=/vms zroot/vms
6. doas vm init
7. cp /usr/local/share/examples/vm-bhyve/* /vms/.templates/
8. vm switch create public
9. vm switch add public em0 (change em0 to whatever your network device is)
10. doas vm iso (insert URL to your distro's image here)
11. doas vm create ubuntu
12. doas vm configure ubuntu
13. doas vm install -f ubuntu ubuntu-20.04.4-desktop-amd64.iso (change this to your image filename)
14. vncviewer (adjust port according to your configuration)
15. doas sysrc vm_list="ubuntu" (autostarts at boot)
16. doas vm start/stop/restart ubuntu

Configuration (adjust accordingly)

Here’s the configuration I use for my setup:

bhyve_options="-s 20,hda,play=/dev/dsp4,rec=/dev/dsp7"

A few notes:

  • I couldn’t get Ubuntu to install with the grub loader, so I switched to uefi. Your case might be different if you use a different distro.
  • The bhyve options are necessary to passthrough your audio. Adjust accordingly.
  • The xhci_mouse part isn’t necessary, but will enable your mousewheel.
  • Graphics resolution can be adjusted to your needs.
  • If you’re running multiple virtual instances, you will need to use unique ports.

GPU passthrough

Unfortunately, you won’t be able to use your GPU passthrough at this time (not yet supported according to docs).

There may be a way around this but I haven’t figured it out yet.

This means that you’re using fbuf which is fine for most tasks, but you won’t be able to run anything graphics-heavy (video editing, gaming, etc.).

If this changes, I’ll update this post.

View Archive