2 # Copyright 1999-2011 Gentoo Foundation
3 # Distributed under the terms of the GNU General Public License v2
4 # $Header: /var/cvsroot/gentoo-x86/sys-fs/zfs/files/zfs,v 0.9 2011/04/30 10:13:43 devsk Exp $
12 CACHEFILE=/etc/zfs/zpool.cache
16 LOCKFILE=/var/lock/zfs/zfs_lockfile
20 /sbin/modinfo $ZFS_MODULE &>/dev/null
23 eerror "$ZFS_MODULE not found. Is the ZFS package installed?"
28 eerror "$ZPOOL binary not found."
33 eerror "$ZFS binary not found."
37 # create the lockdir if not there
38 lockdir=$(dirname ${LOCKFILE})
39 if [[ ! -d ${lockdir} ]]
41 mkdir -p ${lockdir} &>/dev/null
50 einfo "ZFS already running, please stop it first. Delete $LOCKFILE if its not so."
55 checksystem || return 1
56 if ! grep -q $ZFS_MODULE /proc/modules
58 /sbin/modprobe $ZFS_MODULE &>/dev/null
62 eerror "Failed to load the $ZFS_MODULE module, check 'dmesg|tail'."
68 # Ensure / exists in /etc/mtab, if not update mtab accordingly.
69 # This should be handled by rc.sysinit but lets be paranoid.
70 awk '$2 == "/" { exit 1 }' /etc/mtab
72 if [[ $RETVAL -eq 0 ]]
77 # Import all pools described by the cache file, and then mount
78 # all filesystem based on their properties.
79 if [[ -f $CACHEFILE ]]
81 einfo "Importing ZFS pools"
83 # as per fedora script, import can fail if all pools are already imported
84 # The check for $rv makes no sense...but someday, it will work right.
85 $ZPOOL import -c $CACHEFILE -aN 2>/dev/null || true
89 eerror "Failed to import not-yet imported pools."
95 einfo "Mounting ZFS filesystems"
100 eerror "Failed to mount ZFS filesystems."
105 # hack to read mounted file systems because otherwise
106 # zfs returns EPERM when a non-root user reads a mounted filesystem before root did
108 mount | grep " type zfs " | sed 's/.*on //' | sed 's/ type zfs.*$//' | \
111 cd "$line" &> /dev/null
123 if [[ ! -f $LOCKFILE ]]
125 einfo "ZFS is not started, remove $LOCKFILE if its not so."
129 ebegin "Unmounting ZFS filesystems"
134 eerror "Failed to umount ZFS filesystems."
142 if [[ ! -f $LOCKFILE ]]
144 einfo "ZFS is not started, remove $LOCKFILE if its not so."
149 # show pool status and list
150 $ZPOOL status && echo && $ZPOOL list