I would like to be able to run a script at startup that can modify ZFS filesystem properties on "non-root" filesystems prior to the
Examining the output of
Dumping the output of
I'm puzzled as to how to get my script to run after the pools are imported but before they are mounted.
Bonus points for either or both a cleaner way to log output from "early" scripts and how to watch the console output during boot without a Scroll Lock key. As those are arguably off-topic for the sub-forum, let me know if you answer in another thread.
Ordering puzzle resolved in #2, below
/usr/local/etc/rc.d/zfs_defang
zfs mount -a
in the normal boot sequence. The application is a "fail-safe" for backup of root filesystems from other systems that might not have already been marked canmount=noauto
.Examining the output of
rcorder
suggested that between zpool which runs zpool import -c $cachefile -a -N
and zfs which runs zfs mount -va
would be appropriate. My expectation was that only the critical root filesystem would be mounted.Dumping the output of
mount
to a file shows that most everything is mounted. Watching the screen (no Scroll Lock key on my keyboards) suggests that my script is running after Mounting local filesystems:
, even with # BEFORE: zfs mountcritlocal
I'm puzzled as to how to get my script to run after the pools are imported but before they are mounted.
Bonus points for either or both a cleaner way to log output from "early" scripts and how to watch the console output during boot without a Scroll Lock key. As those are arguably off-topic for the sub-forum, let me know if you answer in another thread.
Ordering puzzle resolved in #2, below
While the documentation isn't very clear on this, the script has to be in /etc/rc.d/, not /usr/local/etc/rc.d/
Even if /usr/local/etc/rc.d/ is mounted during early boot, /etc/rc will not look there until after the early-late divider, usually FILESYSTEMS
/usr/local/etc/rc.d/zfs_defang
sh:
#!/bin/sh
#
#
# PROVIDE: zfs_defang
# REQUIRE: zpool root
# BEFORE: zfs mountcritlocal
. /etc/rc.subr
name="zfs_defang"
desc="Override canmount=on for backup pools"
rcvar="zfs_defang_enable"
required_modules="zfs"
start_cmd="zfs_defang_run"
load_rc_config $name
: ${zfs_defang_enable:=NO}
: ${zfs_defang_filesystems:=} # list of filesystems to process
: ${zfs_defang_hostid:=$hostname}
: ${zfs_defang_hostid:=$(sysctl -n kern.hostuuid)}
zfs_defang_run()
{
startmsg
info "hostid is |$zfs_defang_hostid|"
if [ $PPID -eq 1 ] ; then
(
echo
date
rcorder /etc/rc.d/* /usr/local/etc/rc.d/zfs_defang | head -n 50
egrep "^# (PROVIDE|REQUIRE|BEFORE|KEYWORD):" /usr/local/etc/rc.d/zfs_defang
echo "hostid is |$zfs_defang_hostid|"
mount
) >> /root/defang.log
fi
}
run_rc_command "$1"
Code:
Tue Feb 18 12:26:40 PST 2025
/etc/rc.d/natd
/etc/rc.d/dhclient
/etc/rc.d/sysctl
/etc/rc.d/dnctl
/etc/rc.d/dumpon
/etc/rc.d/ddb
/etc/rc.d/hostid
/etc/rc.d/ccd
/etc/rc.d/geli
/etc/rc.d/gbde
/etc/rc.d/swap
/etc/rc.d/zpool
/etc/rc.d/zpoolupgrade
/etc/rc.d/zfskeys
/etc/rc.d/fsck
/etc/rc.d/zpoolreguid
/etc/rc.d/zvol
/etc/rc.d/growfs
/etc/rc.d/root
/etc/rc.d/growfs_fstab
/etc/rc.d/serial
/etc/rc.d/mdconfig
/etc/rc.d/hostid_save
/usr/local/etc/rc.d/zfs_defang
/etc/rc.d/mountcritlocal
/etc/rc.d/var_run
/etc/rc.d/zfsbe
/etc/rc.d/tmp
/etc/rc.d/kldxref
/etc/rc.d/zfs
/etc/rc.d/sysvipc
/etc/rc.d/kld
/etc/rc.d/devmatch
/etc/rc.d/var
/etc/rc.d/linux
/etc/rc.d/localpkg
/etc/rc.d/nuageinit
/etc/rc.d/cfumass
/etc/rc.d/cleanvar
/etc/rc.d/FILESYSTEMS
/etc/rc.d/ipsec
/etc/rc.d/rctl
/etc/rc.d/geli2
/etc/rc.d/autounmountd
/etc/rc.d/adjkerntz
/etc/rc.d/hostname
/etc/rc.d/ip6addrctl
/etc/rc.d/ippool
/etc/rc.d/netoptions
/etc/rc.d/opensm
# PROVIDE: zfs_defang
# REQUIRE: zpool root
# BEFORE: zfs mountcritlocal
hostid is |<redacted>|
backup-host-2025/ROOT/default on / (zfs, local, noatime, nfsv4acls)
devfs on /dev (devfs)
/dev/gpt/efiboot0 on /boot/efi (msdosfs, local)
backup-host-2025 on /zroot (zfs, local, noatime, nfsv4acls)
backup-host-2025/var/log on /var/log (zfs, local, noatime, noexec, nosuid, nfsv4acls)
backup-host-2025/tmp on /tmp (zfs, local, noatime, nosuid, nfsv4acls)
backup-host-2025/home on /home (zfs, local, noatime, nfsv4acls)
backup-host-2025/var/mail on /var/mail (zfs, local, nfsv4acls)
backup-host-2025/var/audit on /var/audit (zfs, local, noatime, noexec, nosuid, nfsv4acls)
backup-host-2025/var/crash on /var/crash (zfs, local, noatime, noexec, nosuid, nfsv4acls)
backup-host-2025/usr/ports on /usr/ports (zfs, local, noatime, nosuid, nfsv4acls)
backup-host-2025/usr/src on /usr/src (zfs, local, noatime, nfsv4acls)
x9-xfer/front-h2/front-h2-boot/BOOT/debian on /boot (zfs, local, nfsv4acls)
backup-2025 on /backup-2025 (zfs, local, nfsv4acls)
backup-host-2025/var/tmp on /var/tmp (zfs, local, noatime, nosuid, nfsv4acls)
[...]