3 # zfs-mount This script will mount/umount the zfs filesystems.
5 # chkconfig: 2345 06 99
6 # description: This script will mount/umount the zfs filesystems during
7 # system boot/shutdown. Configuration of which filesystems
8 # should be mounted is handled by the zfs 'mountpoint' and
9 # 'canmount' properties. See the zfs(8) man page for details.
10 # It is also responsible for all userspace zfs services.
15 # Required-Start: $local_fs zfs-import
16 # Required-Stop: $local_fs zfs-import
17 # Default-Start: 2 3 4 5
19 # X-Stop-After: zfs-zed
20 # Short-Description: Mount ZFS filesystems and volumes
21 # Description: Run the `zfs mount -a` or `zfs umount -a` commands.
24 # Released under the 2-clause BSD license.
26 # The original script that acted as a template for this script came from
27 # the Debian GNU/Linux kFreeBSD ZFS packages (which did not include a
28 # licensing stansa) in the commit dated Mar 24, 2011:
29 # https://github.com/zfsonlinux/pkg-zfs/commit/80a3ae582b59c0250d7912ba794dca9e669e605a
31 # Source the common init script
32 . @sysconfdir@/zfs/zfs-functions
34 # ----------------------------------------------------
39 if [ "$2" = "/" ]; then
42 done < /proc/self/mounts
49 # Try to allow people to mix and match fstab with ZFS in a way that makes sense.
50 if [ "$(mountinfo -s /)" = 'zfs' ]
57 # bootmisc will log to /var which may be a different zfs than root.
58 before bootmisc logger
60 after zfs-import sysfs
62 keyword -lxc -openvz -prefix -vserver
65 # Mount all datasets/filesystems
68 local verbose overlay i mntpt val
70 check_boolean "$VERBOSE_MOUNT" && verbose=v
71 check_boolean "$DO_OVERLAY_MOUNTS" && overlay=O
73 zfs_action "Mounting ZFS filesystem(s)" \
74 "$ZFS" mount -a$verbose$overlay "$MOUNT_EXTRA_OPTIONS"
76 # Require each volume/filesystem to have 'noauto' and no fsck
77 # option. This shouldn't really be necessary, as long as one
78 # can get zfs-import to run sufficiently early on in the boot
79 # process - before local mounts. This is just here in case/if
80 # this isn't possible.
81 check_boolean "$VERBOSE_MOUNT" && \
82 zfs_log_begin_msg "Mounting volumes and filesystems registered in fstab"
84 read_mtab "^/dev/(zd|zvol)"
85 read_fstab "^/dev/(zd|zvol)"
86 i=0; var=$(eval echo FSTAB_$i)
87 while [ -n "$(eval echo "$""$var")" ]
89 mntpt=$(eval echo "$""$var")
90 dev=$(eval echo "$"FSTAB_dev_$i)
91 if ! in_mtab "$mntpt" && ! is_mounted "$mntpt" && [ -e "$dev" ]
93 check_boolean "$VERBOSE_MOUNT" && \
94 zfs_log_progress_msg "$mntpt "
95 fsck "$dev" && mount "$mntpt"
99 var=$(eval echo FSTAB_$i)
102 read_mtab "[[:space:]]zfs[[:space:]]"
103 read_fstab "[[:space:]]zfs[[:space:]]"
104 i=0; var=$(eval echo FSTAB_$i)
105 while [ -n "$(eval echo "$""$var")" ]
107 mntpt=$(eval echo "$""$var")
108 if ! in_mtab "$mntpt" && ! is_mounted "$mntpt"
110 check_boolean "$VERBOSE_MOUNT" && \
111 zfs_log_progress_msg "$mntpt "
116 var=$(eval echo FSTAB_$i)
118 check_boolean "$VERBOSE_MOUNT" && zfs_log_end_msg 0
123 # Unmount all filesystems
128 # This shouldn't really be necessary, as long as one can get
129 # zfs-import to run sufficiently late in the shutdown/reboot process
130 # - after unmounting local filesystems. This is just here in case/if
131 # this isn't possible.
132 zfs_action "Unmounting ZFS filesystems" "$ZFS" unmount -a
134 check_boolean "$VERBOSE_MOUNT" && \
135 zfs_log_begin_msg "Unmounting volumes and filesystems registered in fstab"
137 read_mtab "^/dev/(zd|zvol)"
138 read_fstab "^/dev/(zd|zvol)"
139 i=0; var=$(eval echo FSTAB_$i)
140 while [ -n "$(eval echo "$""$var")" ]
142 mntpt=$(eval echo "$""$var")
143 dev=$(eval echo "$"FSTAB_dev_$i)
146 check_boolean "$VERBOSE_MOUNT" && \
147 zfs_log_progress_msg "$mntpt "
152 var=$(eval echo FSTAB_$i)
155 read_mtab "[[:space:]]zfs[[:space:]]"
156 read_fstab "[[:space:]]zfs[[:space:]]"
157 i=0; var=$(eval echo FSTAB_$i)
158 while [ -n "$(eval echo "$""$var")" ]
160 mntpt=$(eval echo "$""$var")
161 if in_mtab "$mntpt"; then
162 check_boolean "$VERBOSE_MOUNT" && \
163 zfs_log_progress_msg "$mntpt "
168 var=$(eval echo FSTAB_$i)
170 check_boolean "$VERBOSE_MOUNT" && zfs_log_end_msg 0
177 check_boolean "$ZFS_MOUNT" || exit 0
179 check_module_loaded "zfs" || exit 0
181 # Ensure / exists in /proc/self/mounts.
182 # This should be handled by rc.sysinit but lets be paranoid.
193 check_boolean "$ZFS_UNMOUNT" || exit 0
195 check_module_loaded "zfs" || exit 0
200 # ----------------------------------------------------
202 if [ ! -e /sbin/openrc-run ]
211 force-reload|condrestart|reload|restart|status)
215 [ -n "$1" ] && echo "Error: Unknown command $1."
216 echo "Usage: $0 {start|stop}"
223 # Create wrapper functions since Gentoo don't use the case part.
224 depend() { do_depend; }
225 start() { do_start; }