How To Use beadm to Upgrade FreeBSD installed in a ZFS Boot Environment, with minimal downtime

Setting Up the Environment to Build the Updates into the New BootEnvironment.

Before running the build process, you have to make sure to target an alternate installation path. This can be done by setting some environment variables. This is where I make use of the zroot/jails and zroot/jails/devel datasets. I use the devel sub dataset, simply to keep the build process the same as on systems which I am running multiple jails that have more datasets inside the zroot/jails container.

The first step is to mount the new boot environment so its accessible, I am going to use /jails/devel/ROOT as the mount point.

# beadm mount 10.1-RELEASE-p3-r276159-2015.01.09 /jails/devel/ROOT
Mounted successfully on '/jails/devel/ROOT'

Note:  The beadm utility will create the mountpoint for you if its not already there.

I keep a file /jails/devel/setbuild.env that contains commands necessary to set the environment variables. This saves me time typing, I just run cat /jails/devel/setbuild.env, then copy and paste the commands into the console. The MAKEOBJDIRPREFIX and DESTDIR have to be set for this to work. I also set __MAKE_CONF and SRCCONF, this allows you to build the new boot environment using different options than the current one without changing the current one. The last line mounts the /usr/src directory in a read only state to the usr/src path in the boot environment so its accessible in the correct relative path.

cd /jails/devel
cat /jails/devel/setbuild.env
# Jail Environment Build Options
setenv MAKEOBJDIRPREFIX /jails/devel/ROOT/usr/obj
setenv DESTDIR /jails/devel/ROOT
setenv __MAKE_CONF /jails/devel/ROOT/etc/make.conf
setenv SRCCONF /jails/devel/ROOT/etc/src.conf
mount -t nullfs -o ro /usr/src /jails/devel/ROOT/usr/src

Note:  The above code shows the cat of the file, obviously these commands aren't executed until you copy and paste them, I haven't found a way to be able to set the environment variables with a script or I would do it that way instead of this copy and paste. If you know how to do this, please let me know.

Note:  If your not going to use a custom etc/make.conf or etc/src.conf file, do not set those environment variables it will fail if they are set and the file doesn't exist.