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 if [ -z "$init" ]; then
30 grep -qE '(^|[^\\](\\\\)* )zfs=(off|no)( |$)' /proc
/cmdline
&& exit 3
33 # Source function library & LSB routines
34 .
/etc
/rc.d
/init.d
/functions
39 ZPOOL
="@sbindir@/zpool"
40 ZPOOL_CACHE
="@sysconfdir@/zfs/zpool.cache"
42 LOCKFILE
=/var
/lock
/subsys
/$servicename
46 modinfo zfs
> /dev
/null
2>&1 ||
return 5
47 $ZPOOL > /dev
/null
2>&1
48 [ $?
== 127 ] && return 5
50 [ $?
== 127 ] && return 5
55 cat /etc
/mtab |
while read -r fs mntpnt fstype opts rest
; do
56 fs
=`printf '%b\n' "$fs"`
57 mntpnt
=`printf '%b\n' "$mntpnt"`
58 if [ "$fstype" == "zfs" ] ; then
59 if [ "$mntpnt" == "/" ] ; then
60 mount
-f -o zfsutil
-t zfs
--move / /removethismountpointhoweverpossible
61 umount
--fake /removethismountpointhoweverpossible
63 umount
--fake "$mntpnt"
65 elif echo "$fs" |
grep -q "^/dev/zd" ; then
66 if [ "$mntpnt" == "/" ] ; then
67 mount
-f -t "$fstype" --move / /removethismountpointhoweverpossible
68 umount
--fake /removethismountpointhoweverpossible
70 umount
--fake "$mntpnt"
74 cat /proc
/mounts |
while read -r fs mntpnt fstype opts rest
; do
75 fs
=`printf '%b\n' "$fs"`
76 mntpnt
=`printf '%b\n' "$mntpnt"`
77 if [ "$fstype" == "zfs" ] ; then
78 mount
-f -t zfs
-o zfsutil
"$fs" "$mntpnt"
79 elif echo "$fs" |
grep -q "^/dev/zd" ; then
80 mount
-f -t "$fstype" -o "$opts" "$fs" "$mntpnt"
85 # i need a bash guru to simplify this, since this is copy and paste, but donno how
86 # to correctly dereference variable names in bash, or how to do this right
91 # first parameter is a regular expression that filters mtab
93 for fs
in "${!MTAB[@]}" ; do unset MTAB
["$fs"] ; done
94 while read -r fs mntpnt fstype opts blah
; do
95 fs
=`printf '%b\n' "$fs"`
97 done < <(grep "$1" /etc
/mtab
)
101 [ "${MTAB[$1]}" != "" ]
105 # first parameter is a regular expression that filters fstab
107 for fs
in "${!FSTAB[@]}" ; do unset FSTAB
["$fs"] ; done
108 while read -r fs mntpnt fstype opts blah
; do
109 fs
=`printf '%b\n' "$fs"`
111 done < <(grep "$1" /etc
/fstab
)
115 [ "${FSTAB[$1]}" != "" ]
121 if [ -f "$LOCKFILE" ] ; then return 0 ; fi
123 # check if ZFS is installed. If not, comply to FC standards and bail
125 action $
"Checking if ZFS is installed: not installed" /bin
/false
129 # Requires selinux policy which has not been written.
130 if [ -r "/selinux/enforce" ] &&
131 [ "$(cat /selinux/enforce)" = "1" ]; then
132 action $
"SELinux ZFS policy required: " /bin
/false ||
return 6
135 # Delay until all required block devices are present.
138 # load kernel module infrastructure
139 if ! grep -q zfs
/proc
/modules
; then
140 action $
"Loading kernel ZFS infrastructure: " modprobe zfs ||
return 5
143 # fix mtab to include already-mounted fs filesystems, in case there are any
144 # we ONLY do this if mtab does not point to /proc/mounts
145 # which is the case in some systems (systemd may bring that soon)
146 if ! readlink
/etc
/mtab |
grep -q /proc
; then
147 if grep -qE "(^/dev/zd| zfs )" /proc
/mounts
; then
148 action $
"Registering already-mounted ZFS filesystems and volumes: " reregister_mounts ||
return 150
152 if [ -f $ZPOOL_CACHE ] ; then
154 echo -n $
"Importing ZFS pools not yet imported: "
155 $ZPOOL import
-c $ZPOOL_CACHE -aN || true
# stupid zpool will fail if all pools are already imported
157 if [ $RETVAL -ne 0 ]; then
158 failure
"Importing ZFS pools not yet imported: "
161 success
"Importing ZFS pools not yet imported: "
165 action $
"Mounting ZFS filesystems not yet mounted: " $ZFS mount
-a ||
return 152
167 action $
"Exporting ZFS filesystems: " $ZFS share
-a ||
return 153
170 read_fstab
"^/dev/zd"
172 template
=$
"Mounting volume %s registered in fstab: "
173 for volume
in "${!FSTAB[@]}" ; do
174 if in_mtab
"$volume" ; then continue ; fi
175 string
=`printf "$template" "$volume"`
176 action
"$string" mount
"$volume"
184 if [ ! -f "$LOCKFILE" ] ; then return 0 ; fi
186 # check if ZFS is installed. If not, comply to FC standards and bail
188 action $
"Checking if ZFS is installed: not installed" /bin
/false
192 # the poweroff of the system takes care of this
193 # but it never unmounts the root filesystem itself
196 action $
"Syncing ZFS filesystems: " sync
197 # about the only thing we can do, and then we
198 # hope that the umount process will succeed
199 # unfortunately the umount process does not dismount
200 # the root file system, there ought to be some way
201 # we can tell zfs to just flush anything in memory
202 # when a request to remount,ro comes in
204 #echo -n $"Unmounting ZFS filesystems: "
207 #if [ $RETVAL -ne 0 ]; then
217 # See how we are called
228 lsmod |
grep -q zfs || RETVAL
=3
229 $ZPOOL status
&& echo && $ZFS list ||
{
230 [ -f "$LOCKFILE" ] && RETVAL
=2 || RETVAL
=4
238 if [ -f "$LOCKFILE" ] ; then
244 echo $
"Usage: $0 {start|stop|status|restart|condrestart}"