Create jail clones from OpenZFS snapshots

WARNING: the following are my personal notes. Use at your own risk!

1. Creating a Thin Jail Using OpenZFS Snapshots

https://docs.freebsd.org/en/books/handbook/jails/#creating-thin-jail-openzfs-snapshots

Start all configured jails at system boot:

# sysrc jail_enable="YES"
# sysrc jail_parallel_start="YES"

Create datasets for the jail directories:

# zfs create -o mountpoint=/usr/local/jails zroot/jails
# zfs create zroot/jails/media
# zfs create zroot/jails/templates
# zfs create zroot/jails/containers

1.1. Create template jail "ZFS snapshot"

Fetch and patch base, then create snapshot for future clones

# fetch https://download.freebsd.org/ftp/releases/amd64/amd64/13.2-RELEASE/base.txz -o /usr/local/jails/media/13.2-RELEASE-base.txz
# tar -xf /usr/local/jails/media/13.2-RELEASE-base.txz -C /usr/local/jails/templates/13.2-RELEASE --unlink
# freebsd-update -b /usr/local/jails/templates/13.2-RELEASE/ fetch install
# zfs snapshot zroot/jails/templates/13.2-RELEASE@base

1.2. Create new jail "ZFS clone" from template

Clone from snapshot

# zfs clone zroot/jails/templates/13.2-RELEASE@base zroot/jails/containers/thinjail

Copy essential configuration files (OPTIONAL)

# cp /etc/resolv.conf /usr/local/jails/containers/thinjail/etc/resolv.conf
# cp /etc/localtime /usr/local/jails/containers/thinjail/etc/localtime

Create a jail configuration file for the newly created jail in /etc/jail.conf.d:

# ls /etc/jail.conf.d/
thinjail.conf

Start the jail:

# service jail start thinjail

2. Jail Upgrading

https://docs.freebsd.org/en/books/handbook/jails/#jail-upgrading

Upgrade jail to latest patch release:

# freebsd-update -j thinjail fetch install
# service jail restart thinjail

Upgrade jail to new major or minor release:

  1. First upgrade and reboot Host
  2. then upgrade jail:
# freebsd-update -j thinjail -r 13.2-RELEASE upgrade
# freebsd-update -j thinjail install
# service jail restart thinjail
# freebsd-update -j thinjail install
# service jail restart thinjail

Author: https://vieron.info

Created: 2024-11-01 Fri 23:40