Home / Blog /

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

  • 0
  • 2 mins

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 https://releases.ubuntu.com/20.04.4/ubuntu-20.04.4-desktop-amd64.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 127.0.0.1:5999 (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:

loader="uefi"
cpu=8
memory=16G
network0_type="virtio-net"
network0_switch="public"
disk0_type="virtio-blk"
disk0_name="disk0.img"
graphics="yes"
graphics_port="5999"
graphics_listen="0.0.0.0"
graphics_res="1600x900"
graphics_wait="auto"
bhyve_options="-s 20,hda,play=/dev/dsp4,rec=/dev/dsp7"
xhci_mouse="yes"

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 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.

Redpill your friends:
Donovan Nagel
Applied Linguistics graduate, translator and entrepreneur who uses FreeBSD and OpenBSD exclusively for work.
Subscribe to my YouTube channel.

Got something to share?

Comment Policy: This is a free-speech zone but cuntery isn't tolerated. Also no "Linux can do that" flame wars.
All comments are moderated before being published.