Running FreeBSD as a VM guest on Debian 12, using qemu

This entry documents a very basic install of a FreeBSD guest using qemu, since I only need it for porting activities. The qmeu host is headless, so everything is handled via the command line.

First, install the following packages:

  sudo apt install --no-install-recommends qemu-utils qemu-system-x86

Add yourself to the kvm group to allow VM management without becoming root:

  sudo adduser <username> kvm

To provide a home for the VMs, I added a new 100G partition and mounted it on /vm.

Download the FreeBSD 14.0 boot only iso from:

Create a disk image for the FreeBSD VM:

  qemu-img create -f qcow2 /vm/freebsd/disks/freebsd.qcow 30G

Then, start the install with the following command:

  qemu-system-x86_64 -enable-kvm  -m 2G \
    -hda /vm/freebsd/disks/freebsd.qcow \
    -cdrom /vm/freebsd/FreeBSD-14.0-RELEASE-amd64-bootonly.iso -boot d \
    -display curses

This runs the install via a curses-based console. If you want a serial console, run the following commands once the FreeBSD system is installed and you've logged in.

  echo '-S115200 -Dh' > /boot.config
  cat <<EOT >>/boot/loader.conf

Then use -nographic instead of the display option when booting the instance. From this post.

To boot the FreeBSD VM, with no console and access via ssh, the following command may be used:

  qemu-system-x86_64 -enable-kvm  -m 2G \
   -net nic -net user,hostfwd=tcp::2222-:22 \
   -hda /vm/freebsd/disks/freebsd.qcow \
   -display vnc=

This allows an ssh login from the host via port 2222 on the host, which is mapped to port 22 on the guest:

  ssh -p 2222 localhost