Creating FreeBSD Jails with ZFS

by Eric Fortis

This script creates a template jail from a FreeBSD ISO image. Then, it creates the jails by cloning a ZFS snapshot of the template.

…creating a clone is nearly instantaneous, and initially consumes no additional space. ZFS man page
# Create the datasets
zfs create -o mountpoint=/jails zroot/jails
zfs create                      zroot/jails/template

# Mount the ISO image
mkdir -p /mnt/iso
mount_cd9660 /dev/iso9660/14_0_RELEASE_AMD64_CD /mnt/iso

# Create the template jail
tar -xf /mnt/iso/usr/freebsd-dist/base.txz -C /jails/template
umount /mnt/iso

freebsd-update -b /jails/template fetch install
zfs snapshot zroot/jails/template@fresh

# Create the jails from the "fresh" snapshot
for j in foo_j bar_j baz_j; do
  zfs clone zroot/jails/template@fresh zroot/jails/$j

FreeBSD VNET Jails Networking, has an example for the /etc/rc.conf and /etc/jail.conf.

Sponsored by: