Building custom FreeBSD VM images for Incus

Posted on Jan 28, 2025

Recently, I encountered a bug when using Incus on arm64 when using a FreeBSD VM image. Sadly, only the VGA console is working, and with that is the issue of not having input within the console. Reproducing this with Incus on amd64 with a amd64 VM image is not possible.

Luckily, I encountered release allowing creation of VM images. Thanks to Carlo Maiorano I also found out about the ‘VM_RC_LIST’ variable which allows specifying to be enabled services. I used this to enable sshd to get SSH access on the VM as getting correct IP addresses should work normally via Incus dhcp.

Unfortunately, we need an additional step to get into our VM as per default sshd does not allow root login as well as permits empty passwords.

vi /usr/src/sys/openssh/sshd_config
# uncomment and set to yes
PermitRootLogin yes
PermitEmptyPassword yes

WITH_META_MODE=YES TARGET=arm64 TARGET_ARCH=aarch64 VM_RC_LIST=sshd make -j 8 buildworld buildkernel
cd release
 WITH_VMIMAGES=yes VMFORMATS=raw NOPKG=yes NOPORTS=yes NOSRC=yes TARGET=arm64 TARGET_ARCH=aarch64 VM_RC_LIST=sshd VMFORMATS=qcow2 make -j 8 release vm-release

Now we can import the VM image into Incus. This is done similar like NSG proposed:

cat << EOF > metadata.yml
architecture: arm64
creation_date: 1643062675
properties:
    description: FreeBSD 14.2-RELEASE CUSTOM_SSHD
    os: FreeBSD
    release: 14.2-RELEASE 
EOF
tar cf metadata.tar metadata.yaml
incus image import metadata.tar FreeBSD-14.2-RELEASE-CUSTOM-SSHD-CONFIG.qcow2 --alias FreeBSD-14.2-RELEASE-CUSTOM_SSHD

Sadly, it seems that specifying the to be enabled services with ‘VM_RC_LIST’ does not work when issuing make vm-release within /usr/src/release. Within Makefile.vm I found that the environment variables are not passed to the mk-vmimage.sh script.

Note it is also possible to specify extra packages to be installed with ‘VM_EXTRA_PACKAGES’