For a long time, I ran Hermes Agents in FreeBSD Jails – first in FreeBSD jails – I wrote about this in the post Hermes Agent: running an AI Agent in a FreeBSD Jail with Bastille, and later, with a newer version of Hermes, I had to move to Ubuntu jails.
I wrote about containers on FreeBSD with Bastille in FreeBSD: Jails networking and container management with Bastille.
But now that I’ve decided to split the agents into separate instances, which means creating new containers, I realized that I was getting a bit tired of those workarounds with Ubuntu jails.
The problem with Ubuntu jails is that there is no systemd – so I had to start Hermes Gateway and other services with a separate shell script (a hack, basically).
So I decided to explore the world of virtualization on FreeBSD and just create a separate VM with a “clean” Ubuntu installation – and run regular Docker containers with Hermes in it.
This post is more of a purely practical one – I’m not going to compare different systems or dive into networking – just an example of creating and managing virtual machines on FreeBSD with bhyve.
Contents
What is: bhyve
bhyve (“BSD hypervisor“) – the native FreeBSD hypervisor, part of the base system since FreeBSD 10.0, provides full hardware-assisted virtualization – like KVM on Linux:
- supports a separate Linux kernel, its own
systemdand kernel modules - supports UEFI boot (via
edk2-bhyve), virtio disks and networking - provides a VNC console for the installer
- allows you to run Debian, Ubuntu, Arch Linux, etc. without any hassle
Documentation – bhyve.org and bhyve on the FreeBSD Wiki.
FreeBSD: installing bhyve
I’m still running FreeBSD v14.4 on my NAS, see the first post in the series on setting it up, FreeBSD: Home NAS, part 1 – configuring a ZFS mirror.
The “server” itself is a Lenovo ThinkCentre M720s SFF, with an Intel(R) Core(TM) i3-8100 CPU @ 3.60GHz and 24 GB RAM on board.
While we’re at it – here’s what the whole setup looks like:
System preparation
First, check for virtualization support on the hardware itself:
root@setevoy-nas:~ # grep -E 'VT-x|AMD-V|EPT|POPCNT' /var/run/dmesg.boot Features2=0x7ffafbbf<SSE3,PCLMULQDQ,DTES64,MON,DS_CPL,VMX,EST,TM2,SSSE3,SDBG,FMA,CX16,xTPR,PDCM,PCID,SSE4.1,SSE4.2,x2APIC,MOVBE,POPCNT,TSCDLT,AESNI,XSAVE,OSXSAVE,AVX,F16C,RDRAND> VT-x: PAT,HLT,MTF,PAUSE,EPT,UG,VPID
We have:
- VMX + VT-x: Intel hardware virtualization
- EPT (Extended Page Tables): required by bhyve, and we have it (on AMD, this would be NPT – Nested Page Tables)
- UG (unrestricted guest): required to run Linux guests on Intel
- VPID: not required, but improves performance
Installing packages
To manage the machines, we’ll use vm-bhyve (the vm create, vm start commands, etc. – so we don’t have to type miles of command-line options by hand).
For UEFI boot, we’ll add edk2-bhyve.
Install the packages:
root@setevoy-nas:~ # pkg install vm-bhyve edk2-bhyve
...
[2/2] Extracting vm-bhyve-1.7.5: 100%
=====
Message from vm-bhyve-1.7.5:
--
To enable vm-bhyve, please add the following lines to rc.conf,
depending on whether you are using ZFS storage or not. Please note
that the directory or dataset specified should already exist.
vm_enable="YES"
vm_dir="zfs:pool/dataset"
OR
vm_enable="YES"
vm_dir="/directory/path"
Then run 'vm init'.
It might be needed to increase the values of the following tunables.
They need to be high enough to allow for a proper shutdown of all VM's.
- kern.init_shutdown_timeout (adjusted with sysctl.conf)
- rcshutdown_timeout (adjusted with rc.conf)
Creating a ZFS Dataset
We’ll keep the virtual machine data in a separate dataset – bhyve works great with ZFS.
I have one ZFS pool:
root@setevoy-nas:~ # zpool list NAME SIZE ALLOC FREE CKPOINT EXPANDSZ FRAG CAP DEDUP HEALTH ALTROOT nas 3.62T 3.33T 299G - - 23% 91% 1.00x ONLINE -
And the root dataset is nas:
root@setevoy-nas:~ # zfs list -d 1 NAME USED AVAIL REFER MOUNTPOINT nas 3.33T 184G 128K /nas nas/backups-manual 593G 184G 593G /nas/backups-manual nas/bastille 144G 184G 128K /usr/local/bastille ...
Create a new dataset in it, nas/bhyve:
root@setevoy-nas:~ # zfs create nas/bhyve
Check it:
root@setevoy-nas:~ # zfs list nas/bhyve NAME USED AVAIL REFER MOUNTPOINT nas/bhyve 96K 178G 96K /nas/bhyve
Add the bhyve parameters to rc.conf:
root@setevoy-nas:~ # sysrc vm_enable="YES" vm_dir="zfs:nas/bhyve" vm_enable: -> YES vm_dir: -> zfs:nas/bhyve
And run vm init – this just prepares the directories:
root@setevoy-nas:~ # vm init
Now we have the directory structure ready in the new dataset:
root@setevoy-nas:~ # ls -l /nas/bhyve/ total 4 drwxr-xr-x 2 root wheel 4 Nov 22 07:18 .config drwxr-xr-x 2 root wheel 2 Nov 22 07:18 .img drwxr-xr-x 2 root wheel 2 Nov 22 07:18 .iso drwxr-xr-x 2 root wheel 3 Nov 22 07:18 .templates
FreeBSD and bhyve Network Configuration
I already have a bridge interface that I created when setting up Bastille:
root@setevoy-nas:~ # ifconfig -l em0 lo0 bastille0 em0bridge pflog0 e0a_bastille1 e0a_calibre
Here, em0 is the physical interface on the host:
root@setevoy-nas:~ # ifconfig em0
em0: flags=1008943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
options=a500b9<RXCSUM,VLAN_MTU,VLAN_HWTAGGING,JUMBO_MTU,VLAN_HWCSUM,VLAN_HWFILTER,VLAN_HWTSO,RXCSUM_IPV6,HWSTATS>
ether 00:d8:61:f3:bf:f0
inet 192.168.0.211 netmask 0xffffffff broadcast 192.168.0.211
inet 192.168.0.2 netmask 0xffffff00 broadcast 192.168.0.255
inet 192.168.0.214 netmask 0xffffffff broadcast 192.168.0.214
...
The aliases on it belong to the existing jails, as Linux jails in Bastille don’t support VNET.
The bridge interface is em0bridge, and I use it for FreeBSD jails:
root@setevoy-nas:~ # ifconfig em0bridge
em0bridge: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
options=0
ether 58:9c:fc:10:ff:f1
id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
maxage 20 holdcnt 6 proto rstp maxaddr 2000 timeout 1200
root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
member: tap0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
ifmaxaddr 0 port 14 priority 128 path cost 2000000
member: e0a_calibre flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
ifmaxaddr 0 port 10 priority 128 path cost 2000
member: e0a_bastille1 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
ifmaxaddr 0 port 6 priority 128 path cost 2000
member: em0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
ifmaxaddr 0 port 1 priority 128 path cost 2000000
groups: bridge vm-switch viid-4c918@
nd6 options=9<PERFORMNUD,IFDISABLED>
We can use it for networking in our bhyve VMs: vm-bhyve will use this bridge, so the virtual machines’ tap interfaces will simply be added to em0bridge alongside the jails, and the VMs will be on my local 192.168.0.0/24 network.
Create a switch, using the manual option to tell it not to create a new bridge, but to use the existing em0bridge:
root@setevoy-nas:~ # vm switch create -t manual -b em0bridge public
Check it:
root@setevoy-nas:~ # vm switch list NAME TYPE IFACE ADDRESS PRIVATE MTU VLAN PORTS public manual em0bridge n/a no n/a n/a n/a
And that’s it for the preparation – we can move on to the virtual machines now.
Creating a Virtual Machine with Ubuntu
The process here is pretty simple – define a template, download an Ubuntu ISO, start the installation and connect via VNC.
Download Ubuntu ISO
Start downloading the Ubuntu 26.04 ISO:
root@setevoy-nas:~ # vm iso https://releases.ubuntu.com/26.04.1/ubuntu-26.04.1-live-server-amd64.iso
Before creating a new machine, check the CPU and RAM on the host:
root@setevoy-nas:~ # sysctl hw.physmem hw.physmem: 25591488512 root@setevoy-nas:~ # sysctl hw.model hw.ncpu hw.model: Intel(R) Core(TM) i3-8100 CPU @ 3.60GHz hw.ncpu: 4
I have 24 GB of RAM and 4 CPU cores on the NAS.
VM Template
There are template examples on GitHub – sample-templates.
We’ll define our own – create the file /nas/bhyve/.templates/linux-uefi.conf:
# boot via uefi firmware from edk2-bhyve, works with any modern linux installer loader="uefi" # default resources, can be overridden per vm with "vm configure" cpu=2 memory=2G # attach the vm nic to our manual switch on top of em0bridge network0_type="virtio-net" network0_switch="public" # virtio-blk disk, stored as a sparse file inside the vm zfs dataset disk0_type="virtio-blk" disk0_name="disk0.img" # vnc console for the graphical/text installer, wait=no so the vm boots right away graphics="yes" graphics_port="5900" graphics_listen="0.0.0.0" graphics_res="1280x720" xhci_mouse="yes"
Here, we define UEFI boot, default CPU and RAM settings (we can override them when creating a machine), networking, disk and VNC access settings (no password here, as it’s my local home network).
VM create
Create the machine itself. We can do this while the ISO is still downloading – we’ll only need the ISO later, when starting the machine:
root@setevoy-nas:~ # vm create -t linux-uefi -s 40G -m 4G -c 2 ubuntu_test
Here, we specify the UEFI loader, a 40 GB disk, 4 GB RAM and 2 CPU cores.
Check it – we’ve just created the machine, and it’s still in the Stopped state:
root@setevoy-nas:~ # vm list NAME DATASTORE LOADER CPU MEMORY VNC AUTO STATE ubuntu_test default uefi 2 4G - No Stopped
Installing Ubuntu
If the ISO has finished downloading, we can start installing the system.
vm install will start the machine, attach the ISO and enable VNC access:
root@setevoy-nas:~ # vm install ubuntu_test ubuntu-26.04.1-live-server-amd64.iso Starting ubuntu_test * found guest in /nas/bhyve/ubuntu_test * booting...
For VNC on Arch Linux, we can install tigervnc:
[setevoy@setevoy-work ~] $ sudo pacman -S tigervnc
And connect to the NAS/FreeBSD host using its IP and port 5900 (we specified the port in /nas/bhyve/.templates/linux-uefi.conf):
The installer window opens:
I’m not going to describe the Ubuntu installation itself – I think FreeBSD users can figure that one out 🙂
The only thing worth mentioning – don’t forget to install the OpenSSH server right away.
Once the installation is complete, select Reboot now – vm-bhyve in install mode will detach the ISO automatically after the first reboot:
And that’s it for the installation.
Connect via SSH and finish configuring the system.
Production setup
A bit about how I set up the actual “production” machine that I’ll use for Hermes Agents.
Disks configuration
I created two disks – one for the system and one for the data:
# virtio-blk disk, stored as a sparse file inside the vm zfs dataset disk0_type="virtio-blk" disk0_name="system.img" disk1_name="data.img" disk1_type="virtio-blk" disk1_dev="file"
What’s interesting here is that ls will show the “full” size:
root@setevoy-nas:~ # ls -lh /nas/bhyve/hermes-pool/*.img -rw-r--r-- 1 root wheel 256G Nov 24 07:40 /nas/bhyve/hermes-pool/data.img -rw------- 1 root wheel 40G Nov 23 11:57 /nas/bhyve/hermes-pool/system.img
That’s because ls gets the information from the st_size field in the file inode:
root@setevoy-nas:~ # stat -f "size=%z blocks=%b" /nas/bhyve/hermes-pool/data.img size=274877906944 blocks=1
But the actual size is smaller – check it with du:
root@setevoy-nas:~ # du -h /nas/bhyve/hermes-pool/*.img 512B /nas/bhyve/hermes-pool/data.img 512B /nas/bhyve/hermes-pool/system.img
du takes the number of allocated blocks (st_blocks) and multiplies it by 512 bytes (the unit used to count allocated blocks):
root@setevoy-nas:~ # echo $(( $(stat -f %b /nas/bhyve/hermes-pool/data.img) * 512 )) 512
Or check it with zfs list – the size here is a bit larger because it includes the filesystem metadata itself:
root@setevoy-nas:~ # zfs list nas/bhyve/hermes-pool NAME USED AVAIL REFER MOUNTPOINT nas/bhyve/hermes-pool 128K 231G 128K /nas/bhyve/hermes-pool
Next, when installing the system, select the 40 GB disk for root:
The disk partitioning will look like this:
The only thing is that I left the root logical volume at 18 GB when partitioning the disk.
The partitions after the installation:
root@hermes-pool:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS loop0 7:0 0 66.8M 1 loop /snap/core24/1643 loop1 7:1 0 1.5M 1 loop /snap/hwctl/123 loop2 7:2 0 50.1M 1 loop /snap/snapd/27710 sr0 11:0 1 2.7G 1 rom vda 253:0 0 40G 0 disk ├─vda1 253:1 0 1G 0 part /boot/efi ├─vda2 253:2 0 2G 0 part /boot └─vda3 253:3 0 36.9G 0 part └─ubuntu--vg-ubuntu--lv 252:0 0 18.5G 0 lvm / vdb 253:16 0 256G 0 disk
Extend ubuntu--vg-ubuntu--lv:
root@hermes-pool:~# lvextend -r -l +100%FREE /dev/ubuntu-vg/ubuntu-lv File system ext4 found on ubuntu-vg/ubuntu-lv mounted at /. Size of logical volume ubuntu-vg/ubuntu-lv changed from 18.47 GiB (4729 extents) to <36.95 GiB (9458 extents). Extending file system ext4 to <36.95 GiB (39669727232 bytes) on ubuntu-vg/ubuntu-lv... resize2fs /dev/ubuntu-vg/ubuntu-lv resize2fs 1.47.2 (1-Jan-2025) Filesystem at /dev/ubuntu-vg/ubuntu-lv is mounted on /; on-line resizing required old_desc_blocks = 3, new_desc_blocks = 5 The filesystem on /dev/ubuntu-vg/ubuntu-lv is now 9684992 (4k) blocks long. resize2fs done Extended file system ext4 on ubuntu-vg/ubuntu-lv. Logical volume ubuntu-vg/ubuntu-lv successfully resized.
Create a partition on the “large” disk for the data:
root@hermes-pool:~# parted -s /dev/vdb mklabel gpt mkpart hermes-data ext4 1MiB 100%
Format it:
root@hermes-pool:~# mkfs.ext4 -L hermes-data /dev/vdb1
Find the partition UUID:
root@hermes-pool:~# blkid /dev/vdb1 /dev/vdb1: LABEL="hermes-data" UUID="0f563385-6110-40e8-8efe-d78d5960f5e0" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="hermes-data" PARTUUID="441eccc2-2513-4afa-bd64-d9f435d4be0b"
Add it to /etc/fstab:
UUID=0f563385-6110-40e8-8efe-d78d5960f5e0 /data ext4 defaults 0 2
Create the directory itself:
root@hermes-pool:~# mkdir -p /data
Check fstab:
root@hermes-pool:~# systemctl daemon-reload root@hermes-pool:~# findmnt --verify --verbose / [ ] target exists [ ] source /dev/disk/by-id/dm-uuid-LVM-viZCXIQVcjCKB318fZ7M6z9c0ig5aqr6Gsa2PkX860jC00yjygHIEFIIXBOXUF3j exists [ ] FS type is ext4 /boot [ ] target exists [ ] source /dev/disk/by-uuid/b38c4186-32d6-40e2-840a-f57a57417211 exists [ ] FS type is ext4 /boot/efi [ ] target exists [ ] source /dev/disk/by-uuid/78EC-A245 exists [ ] FS type is vfat none [W] non-bind mount source /swap.img is a directory or regular file [ ] FS type is swap /data [ ] target exists [ ] UUID=0f563385-6110-40e8-8efe-d78d5960f5e0 translated to /dev/vdb1 [ ] source /dev/vdb1 exists [ ] FS type is ext4 0 parse errors, 0 errors, 1 warning
Mount the partition:
root@hermes-pool:~# mount /data
And check it:
root@hermes-pool:~# findmnt --mountpoint /data -o TARGET,SOURCE,FSTYPE TARGET SOURCE FSTYPE /data /dev/vdb1 ext4
FreeBSD VM autostart
vm_enable="YES" in rc.conf is something we’ve already set above.
Add the VM to rc.conf so it starts automatically when the host reboots:
root@setevoy-nas:~ # sysrc vm_list="hermes-pool" root@setevoy-nas:~ # sysrc vm_delay="5"
In vm_list we have the list of machines to start, and in vm_delay – the delay between starting them, so they don’t all start at once.
Add new machines to vm_list separated by spaces – sysrc vm_list+=" new-vm-name" – note the space before new-vm-name.
bhyve: basic commands
And a quick look at managing the machines.
Status and management:
vm list: list all machinesvm info ubuntu_test: machine information – resources, MAC, VNC port, disks, tap interfacevm start ubuntu_test: start the VMvm stop ubuntu_test: sendSIGTERM(bhyve translates the signal into a “press” of the ACPI power button in the guest VM, and Ubuntu withsystemd-logindwill perform the shutdown)vm poweroff ubuntu_test: force power off the VMvm restart ubuntu_test: firstvm stop, thenvm start– a “soft reboot”vm reset ubuntu_test: force a VM reboot
Changing machine settings:
vm configure ubuntu_test: open the VM configuration in$EDITOR, the changes take effect after restarting the VM.
Console and logs:
vm console ubuntu_test: connect to the consoletail -f /nas/bhyve/ubuntu_test/vm-bhyve.log: check the VM log
Snapshots and cloning (ZFS):
vm snapshot ubuntu_test@clean-install: create a ZFS snapshot of thenas/bhyve/ubuntu_testdatasetvm rollback ubuntu_test@clean-install: runzfs rollbackvm clone ubuntu_test@clean-install ubuntu_test2: create a new dataset (zfs clone)
See FreeBSD: Home NAS, part 5 – ZFS pool, datasets, snapshots and monitoring.
Right after the installation, we can take a snapshot – then clone new VMs from it in seconds instead of reinstalling the system.
It’s better to perform rollbacks and take snapshots with the VM stopped.
Other useful commands:
vm iso: list downloaded imagesvm switch list: list thevm-bhyvevirtual switches and their settingsvm destroy ubuntu_test: completely remove the machine and all associated data (ZFS dataset, disks, logs)
And we can also perform “low-level” operations with bhyvectl, getting information directly from the system kernel. This only works for running machines.
Detailed VM information:
root@setevoy-nas:~ # bhyvectl --vm=hermes-pool --get-stats vcpu0 stats: number of times in/out was intercepted 346580 number of times cpuid was intercepted 429536 ... Resident memory 4303089664 ... vm exits due to nmi window opening 0
Other useful commands:
bhyvectl --vm=hermes-pool --destroy: destroy the VM instance in the kernel- can clean up a “zombie” when bhyve has crashed, but
/dev/vmm/<name>is still there andvm startwon’t start the machine - on a “live” VM – this kills it instantly, even worse than a poweroff
- can clean up a “zombie” when bhyve has crashed, but
bhyvectl --vm=hermes-pool --force-poweroffand--force-reset: whatvm poweroffandvm resetdo under the hoodbhyvectl --vm=hermes-pool --get-memmapand--get-active-cpus: RAM and CPU information
That’s pretty much it.
In the next post – running Hermes Agent with Docker Compose on this machine.
![]()



