Eric Radman : a Journal

Building Software on OpenBSD in a chroot

Sometimes an experimental build of a large software project requires changes to a running system that are incompatible with the set of packages or configuration on your portable workstation. One solution is to set up a chroot with a full install of the operating system to use as a sandbox.

Unpacking Sources

Before we start we need a dedicated mount point that does not have OpenBSD security-minded flags nodev and nosuid. Languages such as Python we will also need wxallowed.

# fstab
276ec61fa2c663af.a /build ffs,wxallowed rw 1 1

Now with a dedicated mount point we can unpack everything

cd /var/www/htdocs/pub/OpenBSD/6.6/amd64
tar -C /build -xzphf xshare66.tgz
tar -C /build -xzphf xserv66.tgz
tar -C /build -xzphf xfont66.tgz
tar -C /build -xzphf xbase66.tgz
tar -C /build -xzphf man66.tgz
tar -C /build -xzphf game66.tgz
tar -C /build -xzphf comp66.tgz
tar -C /build -xzphf base66.tgz

cd /build/dev
./MAKEDEV all

Porting Configuration

There are a couple files that I want to import into the chroot, namely users

cp /etc/{master.passwd,passwd,group} /build/etc/
mkdir -p /build/home/eradman
chown eradman:users /build/home/eradman

Also missing pieces to allow installation of packages and name resolution

cp /etc/{installurl,resolv.conf} /build/etc/

Finishing the install

The final step is to build the password database, refresh the shared library cache, and populate etc

chroot /build
pwd_mkdb /etc/master.passwd
ldconfig /usr/local/lib
sysmerge