3 # zfs This script will mount/umount the zfs filesystems.
5 # chkconfig: 2345 01 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.
18 # Default-Start: 2 3 4 5
20 # Short-Description: Mount/umount the zfs filesystems
21 # Description: ZFS is an advanced filesystem designed to simplify managing
22 # and protecting your data. This service mounts the ZFS
23 # filesystems and starts all related zfs services.
26 export PATH=/usr/local/sbin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin
28 # Source function library & LSB routines
29 . /etc/rc.d/init.d/functions
34 ZPOOL="@sbindir@/zpool"
35 ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache"
37 LOCKFILE=/var/lock/subsys/$servicename
41 modinfo zfs > /dev/null 2>&1 || return 5
42 $ZPOOL > /dev/null 2>&1
43 [ $? == 127 ] && return 5
45 [ $? == 127 ] && return 5
50 cat /etc/mtab | while read -r fs mntpnt fstype opts rest ; do
51 fs=`printf '%b\n' "$fs"`
52 mntpnt=`printf '%b\n' "$mntpnt"`
53 if [ "$fstype" == "zfs" ] ; then
54 if [ "$mntpnt" == "/" ] ; then
55 mount -f -o zfsutil -t zfs --move / /removethismountpointhoweverpossible
56 umount --fake /removethismountpointhoweverpossible
58 umount --fake "$mntpnt"
60 elif echo "$fs" | grep -q "^/dev/zd" ; then
61 if [ "$mntpnt" == "/" ] ; then
62 mount -f -t "$fstype" --move / /removethismountpointhoweverpossible
63 umount --fake /removethismountpointhoweverpossible
65 umount --fake "$mntpnt"
69 cat /proc/mounts | while read -r fs mntpnt fstype opts rest ; do
70 fs=`printf '%b\n' "$fs"`
71 mntpnt=`printf '%b\n' "$mntpnt"`
72 if [ "$fstype" == "zfs" ] ; then
73 mount -f -t zfs -o zfsutil "$fs" "$mntpnt"
74 elif echo "$fs" | grep -q "^/dev/zd" ; then
75 mount -f -t "$fstype" -o "$opts" "$fs" "$mntpnt"
80 # i need a bash guru to simplify this, since this is copy and paste, but donno how
81 # to correctly dereference variable names in bash, or how to do this right
86 # first parameter is a regular expression that filters mtab
88 for fs in "${!MTAB[@]}" ; do unset MTAB["$fs"] ; done
89 while read -r fs mntpnt fstype opts blah ; do
90 fs=`printf '%b\n' "$fs"`
92 done < <(grep "$1" /etc/mtab)
96 [ "${MTAB[$1]}" != "" ]
100 # first parameter is a regular expression that filters fstab
102 for fs in "${!FSTAB[@]}" ; do unset FSTAB["$fs"] ; done
103 while read -r fs mntpnt fstype opts blah ; do
104 fs=`printf '%b\n' "$fs"`
106 done < <(grep "$1" /etc/fstab)
110 [ "${FSTAB[$1]}" != "" ]
116 if [ -f "$LOCKFILE" ] ; then return 0 ; fi
118 # check if ZFS is installed. If not, comply to FC standards and bail
120 action $"Checking if ZFS is installed: not installed" /bin/false
124 # Requires selinux policy which has not been written.
125 if [ -r "/selinux/enforce" ] &&
126 [ "$(cat /selinux/enforce)" = "1" ]; then
127 action $"SELinux ZFS policy required: " /bin/false || return 6
130 # Delay until all required block devices are present.
133 # load kernel module infrastructure
134 if ! grep -q zfs /proc/modules ; then
135 action $"Loading kernel ZFS infrastructure: " modprobe zfs || return 5
138 # fix mtab to include already-mounted fs filesystems, in case there are any
139 # we ONLY do this if mtab does not point to /proc/mounts
140 # which is the case in some systems (systemd may bring that soon)
141 if ! readlink /etc/mtab | grep -q /proc ; then
142 if grep -qE "(^/dev/zd| zfs )" /proc/mounts ; then
143 action $"Registering already-mounted ZFS filesystems and volumes: " reregister_mounts || return 150
147 if [ -f $ZPOOL_CACHE ] ; then
149 echo -n $"Importing ZFS pools not yet imported: "
150 $ZPOOL import -c $ZPOOL_CACHE -aN || true # stupid zpool will fail if all pools are already imported
152 if [ $RETVAL -ne 0 ]; then
153 failure "Importing ZFS pools not yet imported: "
156 success "Importing ZFS pools not yet imported: "
160 action $"Mounting ZFS filesystems not yet mounted: " $ZFS mount -a || return 152
162 action $"Exporting ZFS filesystems: " $ZFS share -a || return 153
165 read_fstab "^/dev/zd"
167 template=$"Mounting volume %s registered in fstab: "
168 for volume in "${!FSTAB[@]}" ; do
169 if in_mtab "$volume" ; then continue ; fi
170 string=`printf "$template" "$volume"`
171 action "$string" mount "$volume"
179 if [ ! -f "$LOCKFILE" ] ; then return 0 ; fi
181 # check if ZFS is installed. If not, comply to FC standards and bail
183 action $"Checking if ZFS is installed: not installed" /bin/false
187 # the poweroff of the system takes care of this
188 # but it never unmounts the root filesystem itself
191 action $"Syncing ZFS filesystems: " sync
192 # about the only thing we can do, and then we
193 # hope that the umount process will succeed
194 # unfortunately the umount process does not dismount
195 # the root file system, there ought to be some way
196 # we can tell zfs to just flush anything in memory
197 # when a request to remount,ro comes in
199 #echo -n $"Unmounting ZFS filesystems: "
202 #if [ $RETVAL -ne 0 ]; then
212 # See how we are called
223 lsmod | grep -q zfs || RETVAL=3
224 $ZPOOL status && echo && $ZFS list || {
225 [ -f "$LOCKFILE" ] && RETVAL=2 || RETVAL=4
233 if [ -f "$LOCKFILE" ] ; then
239 echo $"Usage: $0 {start|stop|status|restart|condrestart}"