Use ZFS to create a filesystem hierarchy that deal efficiently with disk space, archiving (through snapshot) and offer rollback possibilities (for the upgrade process).

Hierarchy

The layout that will be deployed will extensively use ZFS to hierarchies filesystems and directories, this will facilitate backups, snapshots and rollbacks thereafter, especially since ZFS can do this recursively.

The file hierachy is splitted into four main categories:

Type Description
base the base system making FreeBSD
pkg the applications installed from the packages or port mechanism
distrib the FreeBSD sources (base system and port mechanism)
services the data saved by the various services

The following ZFS hierarchy is proposed and can be adapted depending on the type of installation wanted: base system on ZFS, services (ldap, mysql, imap, …) installed. It is possible to do a lighter or a deeper split, in all cases it will be relatively easy to change this hierarchy on a running system, except for some of the filesystems present on mount points of the base system (ie: /, /usr, /var, …).

  Filesystem Mount point Opt Description
B system/base _Legacy: /   Roof of the operating system
a system/base/tmp /tmp   Directory for temporary files
s system/base/usr /usr   Applications of the base system
e system/base/var /var   Hold files which content is modified (log, lock, spoool, mail, …)
  system/base/var/spool /var/spool   Spool for task processing
  system/base/var/tmp /var/tmp   Directory for temporary files
  system/base/var/empty /var/empty RO Empty directory
  system/base/var/log /var/log   System log files
  system/base/var/db /var/db   Database used by applications (dhcp, ntpd, entropy, …)
P system/pkg /usr/local   Installed packages
k system/pkg/etc /usr/local/etc   Various configuration file for installed packages
g system/pkg/db /var/db/pkg C Information about installed packages
  system/pkg/ports /var/db/ports C Information about options chosen for packages compilation
D system/distrib none A Data for compiling/installing FreeBSD distribution and packages
i system/distrib/src /usr/src C Sources of the FreeBSD base distribution
s system/distrib/ports /usr/ports C Sources and infrastructure necessary for packages compilation
t system/distrib/distfiles /usr/ports/distfiles   Storage of “tarballs” containing the source applications
r system/distrib/pkg /usr/ports/packages   Storing compiled packages (from make package)
i system/distrib/pkg/cache /var/cache/pkg   Fetch packaged (see pkg (8))
b system/build /usr/obj   Intermediate data for distribution/ports compilation
  system/build/cache /var/cache/ccache   Used by ccache when compiling distribution/ports
S system/services none   Data saved by the various services (ie: ldap, mysql, …)
e system/services/ldap /var/db/openldap-data   Data for LDAP
r system/services/mysql /var/db/mysql   Data for MySQL
v system/services/ftp /var/ftp   Data for FTP
i system/services/imap /var/imap   Internal Cyrus IMAP management data
c system/services/imap/mbox /var/spool/imap C User mailboxes
e system/services/imap/meta /var/spool/imap-meta   Metadata for mailboxes
s system/services/imap/sieve /var/spool/sieve   User emails filtering rules

For some snapshots on empty filesystem will be created as an easy way to purge the content if necessary (for example: cache, packages, …)

Purging content
1
zfs rollback filesystem@empty

Creation

Create the pool
1
zpool create system vdev -o mountpoint=none
Creating filesystems for FreeBSD packages
1
2
3
4
zfs create -o mountpoint=/usr/local        -o compress=zstd   system/pkg
zfs create -o mountpoint=/usr/local/etc                       system/pkg/etc
zfs create -o mountpoint=/var/db/pkg                          system/pkg/db 
zfs create -o mountpoint=/var/db/ports                        system/pkg/ports
Creating filesystems for FreeBSD distribution
1
2
3
4
5
6
7
8
9
10
11
12
zfs create -o mountpoint=none                  -o sync=disabled   system/distrib
zfs create -o mountpoint=/usr/src              -o compress=zstd   system/distrib/src 
zfs create -o mountpoint=/usr/ports            -o compress=zstd   system/distrib/ports 
zfs create -o mountpoint=/usr/ports/distfiles                     system/distrib/distfiles
zfs create -o mountpoint=/usr/ports/packages                      system/distrib/pkg
zfs create -o mountpoint=/var/cache/pkg                           system/distrib/pkg/cache
zfs create -o mountpoint=/usr/obj              -o compress=zstd   system/build
zfs create -o mountpoint=/var/cache/ccache     -o compress=lz4    system/build/cache

zfs snapshot system/distrib/distilesj@empty
zfs snapshot system/distrib/pkg/cache@empty
zfs snapshot system/build@empty