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 # This script is based on debian/zfsutils.zfs.init from the
27 # Debian GNU/kFreeBSD zfsutils 8.1-3 package, written by Aurelien Jarno.
29 # Source the common init script
30 . @sysconfdir@/zfs/zfs-functions
32 # ----------------------------------------------------
35 while read -r _ mp _; do
36 if [ "$mp" = "/" ]; then
39 done < /proc/self/mounts
46 # Try to allow people to mix and match fstab with ZFS in a way that makes sense.
47 if [ "$(mountinfo -s /)" = 'zfs' ]
54 # bootmisc will log to /var which may be a different zfs than root.
55 before bootmisc logger
57 after zfs-import sysfs
59 keyword -lxc -openvz -prefix -vserver
62 # Mount all datasets/filesystems
65 local verbose overlay i mntpt
67 check_boolean "$VERBOSE_MOUNT" && verbose=v
68 check_boolean "$DO_OVERLAY_MOUNTS" && overlay=O
70 zfs_action "Mounting ZFS filesystem(s)" \
71 "$ZFS" mount -a$verbose$overlay "$MOUNT_EXTRA_OPTIONS"
73 # Require each volume/filesystem to have 'noauto' and no fsck
74 # option. This shouldn't really be necessary, as long as one
75 # can get zfs-import to run sufficiently early on in the boot
76 # process - before local mounts. This is just here in case/if
77 # this isn't possible.
78 check_boolean "$VERBOSE_MOUNT" && \
79 zfs_log_begin_msg "Mounting volumes and filesystems registered in fstab"
81 read_mtab "^/dev/(zd|zvol)"
82 read_fstab "^/dev/(zd|zvol)"
84 while [ -n "$(eval echo "\$$var")" ]
86 mntpt=$(eval echo "\$$var")
87 dev=$(eval echo "\$FSTAB_dev_$i")
88 if ! in_mtab "$mntpt" && ! is_mounted "$mntpt" && [ -e "$dev" ]
90 check_boolean "$VERBOSE_MOUNT" && \
91 zfs_log_progress_msg "$mntpt "
92 fsck "$dev" && mount "$mntpt"
96 var=$(eval echo "FSTAB_$i")
99 read_mtab "[[:space:]]zfs[[:space:]]"
100 read_fstab "[[:space:]]zfs[[:space:]]"
101 i=0; var=$(eval echo "FSTAB_$i")
102 while [ -n "$(eval echo "\$$var")" ]
104 mntpt=$(eval echo "\$$var")
105 if ! in_mtab "$mntpt" && ! is_mounted "$mntpt"
107 check_boolean "$VERBOSE_MOUNT" && \
108 zfs_log_progress_msg "$mntpt "
113 var=$(eval echo "FSTAB_$i")
115 check_boolean "$VERBOSE_MOUNT" && zfs_log_end_msg 0
120 # Unmount all filesystems
125 # This shouldn't really be necessary, as long as one can get
126 # zfs-import to run sufficiently late in the shutdown/reboot process
127 # - after unmounting local filesystems. This is just here in case/if
128 # this isn't possible.
129 zfs_action "Unmounting ZFS filesystems" "$ZFS" unmount -a
131 check_boolean "$VERBOSE_MOUNT" && \
132 zfs_log_begin_msg "Unmounting volumes and filesystems registered in fstab"
134 read_mtab "^/dev/(zd|zvol)"
135 read_fstab "^/dev/(zd|zvol)"
137 while [ -n "$(eval echo "\$$var")" ]
139 mntpt=$(eval echo "\$$var")
140 dev=$(eval echo "\$FSTAB_dev_$i")
143 check_boolean "$VERBOSE_MOUNT" && \
144 zfs_log_progress_msg "$mntpt "
149 var=$(eval echo "FSTAB_$i")
152 read_mtab "[[:space:]]zfs[[:space:]]"
153 read_fstab "[[:space:]]zfs[[:space:]]"
155 while [ -n "$(eval echo "\$$var")" ]
157 mntpt=$(eval echo "\$$var")
158 if in_mtab "$mntpt"; then
159 check_boolean "$VERBOSE_MOUNT" && \
160 zfs_log_progress_msg "$mntpt "
165 var=$(eval echo "FSTAB_$i")
167 check_boolean "$VERBOSE_MOUNT" && zfs_log_end_msg 0
174 check_boolean "$ZFS_MOUNT" || exit 0
176 check_module_loaded "zfs" || exit 0
178 # Ensure / exists in /proc/self/mounts.
179 # This should be handled by rc.sysinit but lets be paranoid.
190 check_boolean "$ZFS_UNMOUNT" || exit 0
192 check_module_loaded "zfs" || exit 0
197 # ----------------------------------------------------
199 if [ ! -e /sbin/openrc-run ]
208 force-reload|condrestart|reload|restart|status)
212 [ -n "$1" ] && echo "Error: Unknown command $1."
213 echo "Usage: $0 {start|stop}"
220 # Create wrapper functions since Gentoo don't use the case part.
221 depend() { do_depend; }
222 start() { do_start; }