#!/bin/sh # # $FreeBSD: head/libexec/rc/rc.d/zfs 307182 2016-10-13 06:19:54Z avg $ # # PROVIDE: zfs # REQUIRE: zfsbe # BEFORE: FILESYSTEMS var . /etc/rc.subr name="zfs" desc="Mount and share ZFS datasets" rcvar="zfs_enable" start_cmd="zfs_start" 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_enable=${zfs_ordered_mount_enable:-"NO"} zfs_start_jail() { if [ `$SYSCTL_N security.jail.mount_allowed` -eq 1 ]; then zfs mount -a fi } zfs_start_main() { if checkyesno zfs_ordered_mount_enable; then local _zroot _zpool _zroot=`df -t zfs / | tail -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 _fs1 _fs2 _fs1=`zfs list -Hro mountpoint,name -t filesystem ${1} | egrep -ve '^legacy|^none' | awk '{print $2}'` for _fs2 in `zfs list -Hro canmount,name -t filesystem ${_fs1} | egrep -ve ^off | awk '{print $2}'`; do if [ "`zfs get -Ho value mounted ${_fs2}`" = no ]; then zfs mount -v ${_fs2} fi done } zfs_start() { if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then zfs_start_jail else zfs_start_main fi } zfs_stop_jail() { if [ `$SYSCTL_N security.jail.mount_allowed` -eq 1 ]; then zfs unmount -a fi } zfs_stop_main() { zfs unshare -a zfs unmount -a } zfs_stop() { if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then zfs_stop_jail else zfs_stop_main fi } load_rc_config $name run_rc_command "$1"