xref: /freebsd/libexec/rc/rc.d/zfsbe (revision e32fecd0c2c3ee37c47ee100f169e7eb0282a873)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# PROVIDE: zfsbe
7# REQUIRE: mountcritlocal
8
9# Handle boot environment subordinate filesystems
10# that may have canmount property set to noauto.
11# For these filesystems mountpoint relative to /
12# must be the same as their dataset name relative
13# to BE root dataset.
14
15. /etc/rc.subr
16
17name="zfsbe"
18rcvar="zfs_enable"
19start_cmd="be_start"
20stop_cmd="be_stop"
21required_modules="zfs"
22
23mount_subordinate()
24{
25	local _be
26
27	_be=$1
28	zfs list -rH -o mountpoint,name,canmount,mounted -s mountpoint -t filesystem $_be | \
29	while read _mp _name _canmount _mounted ; do
30		# skip filesystems that must not be mounted
31		[ "$_canmount" = "off" ] && continue
32		# skip filesystems that are already mounted
33		[ "$_mounted" = "yes" ] && continue
34		case "$_mp" in
35		"none" | "legacy" | "/" | "/$_be")
36			# do nothing for filesystems with unset or legacy mountpoint
37			# or those that would be mounted over /
38			;;
39		"/$_be/"*)
40			# filesystems with mountpoint relative to BE
41			mount -t zfs $_name ${_mp#/$_be}
42			;;
43		*)
44			# filesystems with mountpoint elsewhere
45			zfs mount $_name
46			;;
47		esac
48	done
49}
50
51activate_bootonce()
52{
53	local _dev
54	local _bootonce
55	local _be
56
57	_dev=$1
58	_be=${_dev##*/}
59
60	_bootonce=$(kenv -q zfs-bootonce)
61	if [ "$_bootonce" = "zfs:${_dev}:" ] ; then
62		bectl activate $_be
63	fi
64}
65
66be_start()
67{
68	if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then
69		:
70	else
71		mount -p | while read _dev _mp _type _rest; do
72			[ $_mp  = "/" ] || continue
73			if [ $_type = "zfs" ] ; then
74				mount_subordinate $_dev
75				if checkyesno zfs_bootonce_activate; then
76					activate_bootonce $_dev
77				fi
78			fi
79			break
80		done
81	fi
82}
83
84be_stop()
85{
86}
87
88load_rc_config $name
89run_rc_command "$1"
90