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

Setting Up A Jail

The next file, will be the /jails/devel/prestart.sh script. This script changes your jailed environment so its not starting services, and mounts some nullfs file systems to make sure things are in the right location within the jail.

#!/bin/sh
# Change to Development Jail rc.conf
cp /jails/devel/ROOT/etc/rc.conf /jails/devel/ROOT/etc/rc.conf.normal
cp /jails/devel/ROOT/etc/rc.conf.jail /jails/devel/ROOT/etc/rc.conf
# Remove sysctl.conf from jail
mv /jails/devel/ROOT/etc/sysctl.conf /jails/devel/ROOT/etc/sysctl.conf.normal
touch /jails/devel/ROOT/etc/sysctl.conf
# Remove fstab from jail
mv /jails/devel/ROOT/etc/fstab /jails/devel/ROOT/etc/fstab.normal
touch /jails/devel/ROOT/etc/fstab
# Mount File Systems
/sbin/mount_nullfs -o ro /usr/src /jails/devel/ROOT/usr/src
/sbin/mount_nullfs -o ro /usr/ports /jails/devel/ROOT/usr/ports
/sbin/mount_nullfs -o rw /usr/ports/distfiles /jails/devel/ROOT/usr/ports/distfiles

The next file, will be the /jails/devel/posfstop.sh script. This script dismounts the nullfs file systems, and returns the normal configuration files.

#!/bin/sh
# Change Back To Normal rc.conf
cp /jails/devel/ROOT/etc/rc.conf /jails/devel/ROOT/etc/rc.conf.jail
cp /jails/devel/ROOT/etc/rc.conf.normal /jails/devel/ROOT/etc/rc.conf
# Change Back To sysctl.conf
cp /jails/devel/ROOT/etc/sysctl.conf.normal /jails/devel/ROOT/etc/sysctl.conf
# Change Back To fstab
cp /jails/devel/ROOT/etc/fstab.normal /jails/devel/ROOT/etc/fstab
# Dismount Jail File Systems
/sbin/umount /jails/devel/ROOT/usr/ports/distfiles
/sbin/umount /jails/devel/ROOT/usr/ports
/sbin/umount /jails/devel/ROOT/usr/src

Note:  These scripts will be called automatically when the jail is started and stopped.