Can I use this script to create a ZFS filesystem on a partition?
That script is ancient:
"shigeyas/setup-zfs-root-filesystem.sh
Created 14 years ago"
It creates zroot/usr/home datasets. The official installer creates zroot/home for some time now.
Use the script down below. It is extracted from a 15.0-RELEASE bsdinstaller_log.
Save it on the iso (
bsdinstall(8), see BUILDING AUTOMATIC INSTALL MEDIA), and copy during installation to /tmp to edit, or fetch it during install from LAN into /tmp of installer media. /tmp and /var are the only writable directories when booting the iso.
Boot installer media, start menu guided installation, at the "Partitioning" menu enter "Shell", create manual GPT scheme and partitions (ESP- efi, freebsd-swap, freebsd-zfs), create ESP, copy loader.efi, execute ZFS pool-dataset creator script, exit "Shell", continue with installation. At the end check /boot/loader.conf, /etc/fstab, /etc/rc.conf, /etc/sysctl.conf.
Make sure to get the device name right.
Code:
#!/bin/sh
#
# shell script extracted from /var/log/bsdinstall_log
# Creating root pool
# Replace "ada0pX" with actual device name
zpool create -o ashift=12 -o altroot=/mnt -O compress=lz4 -O atime=off -m none -f zroot ada0pX
# Creating ZFS datasets
zfs create -o mountpoint=none zroot/ROOT
zfs create -o mountpoint=/ zroot/ROOT/default
zfs create -o mountpoint=/home zroot/home
zfs create -o mountpoint=/tmp -o exec=on -o setuid=off zroot/tmp
zfs create -o mountpoint=/usr -o canmount=off zroot/usr
zfs create -o setuid=off zroot/usr/ports
zfs create zroot/usr/src
zfs create -o mountpoint=/var -o canmount=off zroot/var
zfs create -o exec=off -o setuid=off zroot/var/audit
zfs create -o exec=off -o setuid=off zroot/var/crash
zfs create -o exec=off -o setuid=off zroot/var/log
zfs create -o atime=on zroot/var/mail
zfs create -o setuid=off zroot/var/tmp
# Setting mountpoint for root of the pool
zfs set mountpoint=/zroot zroot
# Modifying directory permissions
mkdir -p /mnt/tmp
chmod 1777 /mnt/tmp
mkdir -p /mnt/var/tmp
chmod 1777 /mnt/var/tmp
# Setting bootfs property
zpool set bootfs=zroot/ROOT/default zroot
# Configuring zpool.cache for zroot
mkdir -p /mnt/boot/zfs
zpool set cachefile=/mnt/boot/zfs/zpool.cache zroot
# Set canmount=noauto for any datasets under the BE
zfs set canmount=noauto zroot/ROOT/default