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