--- zfs 2016-10-13 08:19:54.000000000 +0200 +++ zfs 2019-05-20 13:17:04.686796000 +0200 @@ -16,6 +16,20 @@ stop_cmd="zfs_stop" required_modules="zfs" +# +# Add the following lines to /etc/rc.conf to enable ZFS ordered mount: +# zfs_ordered_mount_enable (bool): Mount ZFS in order (or NO). +# zfs_ordered_mount_zpoolname_egrep_filter (str): Optional egrep(1) pattern for filtering unwanted filesystems, one per zpool. +# Filesystems having canmount=off will be excluded automatically. +# +# Example: +# zfs_ordered_mount_enable="YES" +# zfs_ordered_mount_zroot_egrep_filter="zroot\$|zroot/ROOT|zroot/do-not-destroy" +# zfs_ordered_mount_zdata_egrep_filter="zdata\$|zdata/do-not-destroy" +# + +zfs_ordered_mount_enable=${zfs_ordered_mount_enable:-"NO"} + zfs_start_jail() { if [ `$SYSCTL_N security.jail.mount_allowed` -eq 1 ]; then @@ -25,11 +39,43 @@ zfs_start_main() { - zfs mount -va + if checkyesno zfs_ordered_mount_enable; then + local _zroot _zpool + + _zroot=`df -t zfs / | tail -1 | awk '{print $1}' | cut -d / -f 1` + + if [ -n "${_zroot}" ]; then + zfs_mount_pool ${_zroot} + fi + + for _zpool in `zpool list -Ho name`; do + if [ "${_zpool}" != "${_zroot}"; then + zfs_mount_pool ${_zpool} + fi + done + else + zfs mount -va + fi zfs share -a if [ ! -r /etc/zfs/exports ]; then touch /etc/zfs/exports fi +} + +zfs_mount_pool() +{ + local _zpool _egrep_filter_name _egrep_filter _fs + _zpool=${1} + + _egrep_filter_name=zfs_ordered_mount_${_zpool}_egrep_filter + _egrep_filter=`eval echo \$\{${_egrep_filter_name}\}` + if [ -n "${_egrep_filter}" ]; then + # Need to separate our ^off from the user's specification. + _egrep_filter="|${_egrep_filter}" + fi + for _fs in `zfs list -Hro canmount,name -t filesystem ${_zpool} | egrep -ve "^off${_egrep_filter}" | awk '{print $2}'`; do + zfs mount -v ${_fs} + done } zfs_start()