xref: /freebsd/libexec/rc/rc.d/zfsbe (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
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
51be_start()
52{
53	if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then
54		:
55	else
56		mount -p | while read _dev _mp _type _rest; do
57			[ $_mp  = "/" ] || continue
58			if [ $_type = "zfs" ] ; then
59				mount_subordinate $_dev
60			fi
61			break
62		done
63	fi
64}
65
66be_stop()
67{
68}
69
70load_rc_config $name
71run_rc_command "$1"
72