]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - etc/rc.d/zfsbe
MFC r307182,307191,307192: rc.d/zfsbe: new script designed for BE support
[FreeBSD/stable/10.git] / etc / rc.d / zfsbe
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
17 name="zfsbe"
18 rcvar="zfs_enable"
19 start_cmd="be_start"
20 stop_cmd="be_stop"
21 required_modules="zfs"
22
23 mount_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
51 be_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
66 be_stop()
67 {
68 }
69
70 load_rc_config $name
71 run_rc_command "$1"