xref: /freebsd/libexec/rc/rc.d/zfsbe (revision f99f0ee14e3af81c23150a6a340259ca8a33d01a)
10696600cSBjoern A. Zeeb#!/bin/sh
20696600cSBjoern A. Zeeb#
30696600cSBjoern A. Zeeb#
40696600cSBjoern A. Zeeb
50696600cSBjoern A. Zeeb# PROVIDE: zfsbe
60696600cSBjoern A. Zeeb# REQUIRE: mountcritlocal
70696600cSBjoern A. Zeeb
80696600cSBjoern A. Zeeb# Handle boot environment subordinate filesystems
90696600cSBjoern A. Zeeb# that may have canmount property set to noauto.
100696600cSBjoern A. Zeeb# For these filesystems mountpoint relative to /
110696600cSBjoern A. Zeeb# must be the same as their dataset name relative
120696600cSBjoern A. Zeeb# to BE root dataset.
130696600cSBjoern A. Zeeb
140696600cSBjoern A. Zeeb. /etc/rc.subr
150696600cSBjoern A. Zeeb
160696600cSBjoern A. Zeebname="zfsbe"
170696600cSBjoern A. Zeebrcvar="zfs_enable"
180696600cSBjoern A. Zeebstart_cmd="be_start"
190696600cSBjoern A. Zeebstop_cmd="be_stop"
200696600cSBjoern A. Zeebrequired_modules="zfs"
210696600cSBjoern A. Zeeb
220696600cSBjoern A. Zeebmount_subordinate()
230696600cSBjoern A. Zeeb{
240696600cSBjoern A. Zeeb	local _be
250696600cSBjoern A. Zeeb
260696600cSBjoern A. Zeeb	_be=$1
270696600cSBjoern A. Zeeb	zfs list -rH -o mountpoint,name,canmount,mounted -s mountpoint -t filesystem $_be | \
280696600cSBjoern A. Zeeb	while read _mp _name _canmount _mounted ; do
290696600cSBjoern A. Zeeb		# skip filesystems that must not be mounted
300696600cSBjoern A. Zeeb		[ "$_canmount" = "off" ] && continue
310696600cSBjoern A. Zeeb		# skip filesystems that are already mounted
320696600cSBjoern A. Zeeb		[ "$_mounted" = "yes" ] && continue
330696600cSBjoern A. Zeeb		case "$_mp" in
340696600cSBjoern A. Zeeb		"none" | "legacy" | "/" | "/$_be")
350696600cSBjoern A. Zeeb			# do nothing for filesystems with unset or legacy mountpoint
360696600cSBjoern A. Zeeb			# or those that would be mounted over /
370696600cSBjoern A. Zeeb			;;
380696600cSBjoern A. Zeeb		"/$_be/"*)
390696600cSBjoern A. Zeeb			# filesystems with mountpoint relative to BE
400696600cSBjoern A. Zeeb			mount -t zfs $_name ${_mp#/$_be}
410696600cSBjoern A. Zeeb			;;
420696600cSBjoern A. Zeeb		*)
430696600cSBjoern A. Zeeb			# filesystems with mountpoint elsewhere
440696600cSBjoern A. Zeeb			zfs mount $_name
450696600cSBjoern A. Zeeb			;;
460696600cSBjoern A. Zeeb		esac
470696600cSBjoern A. Zeeb	done
480696600cSBjoern A. Zeeb}
490696600cSBjoern A. Zeeb
50e307eb94SToomas Soomeactivate_bootonce()
51e307eb94SToomas Soome{
52e307eb94SToomas Soome	local _dev
53e307eb94SToomas Soome	local _bootonce
54e307eb94SToomas Soome	local _be
55e307eb94SToomas Soome
56e307eb94SToomas Soome	_dev=$1
57e307eb94SToomas Soome	_be=${_dev##*/}
58e307eb94SToomas Soome
590c4183f0SWarner Losh	_bootonce=$(kenv -q zfs-bootonce)
60e307eb94SToomas Soome	if [ "$_bootonce" = "zfs:${_dev}:" ] ; then
61e307eb94SToomas Soome		bectl activate $_be
62e307eb94SToomas Soome	fi
63e307eb94SToomas Soome}
64e307eb94SToomas Soome
650696600cSBjoern A. Zeebbe_start()
660696600cSBjoern A. Zeeb{
670696600cSBjoern A. Zeeb	if [ `$SYSCTL_N security.jail.jailed` -eq 1 ]; then
680696600cSBjoern A. Zeeb		:
690696600cSBjoern A. Zeeb	else
700696600cSBjoern A. Zeeb		mount -p | while read _dev _mp _type _rest; do
710696600cSBjoern A. Zeeb			[ $_mp  = "/" ] || continue
720696600cSBjoern A. Zeeb			if [ $_type = "zfs" ] ; then
730696600cSBjoern A. Zeeb				mount_subordinate $_dev
74e307eb94SToomas Soome				if checkyesno zfs_bootonce_activate; then
75e307eb94SToomas Soome					activate_bootonce $_dev
76e307eb94SToomas Soome				fi
770696600cSBjoern A. Zeeb			fi
780696600cSBjoern A. Zeeb			break
790696600cSBjoern A. Zeeb		done
800696600cSBjoern A. Zeeb	fi
810696600cSBjoern A. Zeeb}
820696600cSBjoern A. Zeeb
830696600cSBjoern A. Zeebbe_stop()
840696600cSBjoern A. Zeeb{
850696600cSBjoern A. Zeeb}
860696600cSBjoern A. Zeeb
870696600cSBjoern A. Zeebload_rc_config $name
88*f99f0ee1SAlexander Leidinger
89*f99f0ee1SAlexander Leidinger# doesn't make sense to run in a svcj: mounting / config setting
90*f99f0ee1SAlexander Leidingerzfsbe_svcj="NO"
91*f99f0ee1SAlexander Leidinger
920696600cSBjoern A. Zeebrun_rc_command "$1"
93