Developing with FreeBSD
Preamble
I've usually dealt with Linux based systems (such as Ubuntu, Fedora, CentOS, RedHat) as part of my work or personal projects. Sometimes, I venture into Windows and macOS, but rarely do I get a chance to get into other Unix variants such as FreeBSD. Infact, the last time I worked on this and other distros such as OpenBSD, NetBSD, Sun Solaris, SCO UNIX, was when I worked at Adaptec Inc. (around 2007), on RAID storage management software. Their driver and software had to support many operating systems, the esoteric ones too.
So, I jumped at the opportunity when roc-streaming needed some contributions to support FreeBSD. I needed the excuse. Here is how I went about setting it up.
Getting up a FreeBSD VM running
I usually work on Ubuntu (currently Ubuntu 24.04.3 LTS), so the easiest (and user-friendliest) way to install FreeBSD-14.3 is to use VirtualBox. I went to the virtualbox website and downloaded the deb package for Ubuntu 24.04 and followed the Debian-based Linux distributions further below.
I then launched "Oracle VirtualBox Manager". (I think there are other non-branded versions of VirtualBox, possibly shipped within the distro itself) and created a new VM with enough storage (32 GB). I downloaded a FreeBSD iso dvd from here and used it as my second installation disk and started the VM, with the error message, VT-x is being used by another hypervisor (VERR_VMX_IN_VMX_ROOT_MODE).

What the actual! There's another hypervisor already running?
After some searching, it turns out there's a kvm kernel module that is running which stops the Intel VT-x form being used:
nolan-veed@nolan-veed:~$ lsmod | grep kvm
kvm_intel 487424 0
kvm 1425408 1 kvm_intel
irqbypass 12288 1 kvm
nolan-veed@nolan-veed:~$ modinfo kvm_intel
filename: /lib/modules/6.14.0-33-generic/kernel/arch/x86/kvm/kvm-intel.ko.zst
license: GPL
description: KVM support for VMX (Intel VT-x) extensions
...
I can temporarily disable this, because I'm not using kvm on my laptop:
nolan-veed@nolan-veed:~$ sudo modprobe -r kvm_intel
nolan-veed@nolan-veed:~$ lsmod | grep kvm
Then my VM starts, and I can go through the FreeBSD installation screens.
Configuring SSH access
Once rebooted, I find it important to have SSH access. This is because it tends to become tedious switching between the VM and the host machine. I also tend to do most of the work on the host machine, in VSCode for example.
So, upon your first login as root, simply edit the /etc/ssh/sshd_config file, ensuring these lines are properly setup:
...
PermitRootLogin yes
...
PasswordAuthentication yes
Then restart the service:
service sshd restart
Also change your root password. (It's usually empty by default.)
And test from the host using:
ssh root@<ip-address>
You can get the ip address of your VM using ifconfig. (It's easier if you use a "Bridged Adapter" in VirtualBox VM settings for the network interface.)
Once ssh is confirmed to be working. You can also authorize your ssh key, just makes life easier:
ssh-copy-id root@<ip-address>
Setting up for software development
I generally, use VSCode for software development. So, in the case of roc-toolkit, I clone the repo on my host machine and opened it in VSCode.
I then mount it on the the FreeBSD VM through sshfs. For this, you'll need to do the following on the VM:
# Install the package.
pkg install fusefs-sshfs
# Load the kernel module
kldload fusefs
# Mount a host machine's directory
sshfs -o idmap=user nolan-veed@<host-ip-address>:nolan-veed/roc-toolkit roc-toolkit
I can then work with VSCode and run any build commands on a FreeBSD terminal through ssh.
Wrap up
That's enough for now. But, I have a few things to do. There are some nicer ways of doing things for what I want (perhaps for another post):
- We can try some already installed FreeBSD disk images - there are CI and CLOUD-INIT images.
- We can use qemu-system-x86_64 to run disk images, instead of a full blown VMM, like VirtualBox.
For the task at hand, I was able to fix the roc-toolkit build and run tests. I then and create a PR for it. The next thing for me to look into is how we get this to build in CI, specifically through GitHub Actions. For this, there are some cool GitHub Actions already available from vmactions, and for quite a few bsds too. For FreeBSD, I can use this one. It it works through libvirt and qemu.
- ← Previous
Atomics in cache lines