Random Musings

O for a muse of fire, that would ascend the brightest heaven of invention!


Building from Source, in a Jail

Wednesday, 22 Jan 2025 Tags: notesrelengsource

As part of being more involved in FreeBSD release engineering work, I need to test my builds in a clean environment. This is a quick guide on how I do that right now. In the near future this will be fully automated.

First up, we will need:

  • a jail
  • nullfs-mounted /usr/src

Creating the Jail

The most important jail settings are:

  • allow.chflags
  • allow.mount
  • allow.mount.devfs
  • allow.mount.tmpfs

I made a 14.2-RELEASE jail called picard using those settings.

Setting up the Jail

# mount_nullfs -o ro /usr/src /jails/tags/picard/usr/src
# mount -t tmpfs tmpfs /jails/tags/picard/usr/obj
# sed -i'' -e s/quarterly/latest/ /jails/tags/picard/etc/pkg/FreeBSD.conf
# jexec picard pkg install -qyr FreeBSD \
  git-lite qemu-user-static qemu-tools curl tmux

Building Things

Enter the jail, build the things.

The git config line is to ensure that GITREV is populated, so that the build artifacts have this in their name.

If I’m ready to upload artifacts, I set ORACLE_PAR_URL as well. You can set this to file:///var/tmp if you don’t want to actually upload these to the Cloud.

# jexec picard tmux -u new -DAs default

# cd /usr/src
# git config --global --add safe.directory /usr/src
# cd /usr/src && make -j32 buildworld  TARGET_ARCH=amd64 TARGET=amd64 -s \
  && make -j32 buildkernel TARGET_ARCH=amd64 TARGET=amd64 KERNCONF=GENERIC -s \
  && cd ./release \
  && make TARGET_ARCH=amd64 TARGET=amd64  -j32 -s clean \
  && make  KERNCONF=GENERIC TARGET_ARCH=amd64 TARGET=amd64 \
    WITH_CLOUDWARE=yes \
    CLOUDWARE=ORACLE \
    -s clean cloudware-release cw-oracle-upload

# cd /usr/src && make -j32 buildworld  TARGET_ARCH=aarch64 TARGET=arm64 -s \
  && make -j32 buildkernel TARGET_ARCH=aarch64 TARGET=arm64 KERNCONF=GENERIC -s \
  && cd ./release \
  && make -j32 TARGET_ARCH=aarch64 TARGET=arm64 -s clean \
  && make  KERNCONF=GENERIC TARGET_ARCH=aarch64 TARGET=arm64 \
    WITH_CLOUDWARE=yes \
    CLOUDWARE=ORACLE \
    -s clean cloudware-release cw-oracle-upload

After a wee while, there will be build artifacts in /usr/obj/usr/src/*/release/*.oci ready for upload.