2011-05-03 02:39:59 +04:00
|
|
|
#!/sbin/runscript
|
|
|
|
# Copyright 1999-2011 Gentoo Foundation
|
2012-07-10 17:27:09 +04:00
|
|
|
# Released under the 2-clause BSD license.
|
2011-05-03 02:39:59 +04:00
|
|
|
# $Header: /var/cvsroot/gentoo-x86/sys-fs/zfs/files/zfs,v 0.9 2011/04/30 10:13:43 devsk Exp $
|
|
|
|
|
2013-04-14 19:41:51 +04:00
|
|
|
if [ -z "$init" ]; then
|
|
|
|
# Not interactive
|
|
|
|
grep -Eqi 'zfs=off|zfs=no' /proc/cmdline && exit 3
|
|
|
|
fi
|
|
|
|
|
2011-05-03 02:39:59 +04:00
|
|
|
depend()
|
|
|
|
{
|
2013-05-29 04:08:15 +04:00
|
|
|
# Try to allow people to mix and match fstab with ZFS in a way that makes sense.
|
|
|
|
if [ "$(mountinfo -s /)" = 'zfs' ]
|
|
|
|
then
|
|
|
|
before localmount
|
|
|
|
else
|
|
|
|
after localmount
|
|
|
|
fi
|
|
|
|
|
2011-07-05 01:58:51 +04:00
|
|
|
# bootmisc will log to /var which may be a different zfs than root.
|
2013-05-29 04:08:15 +04:00
|
|
|
before bootmisc logger
|
2011-05-10 23:45:19 +04:00
|
|
|
keyword -lxc -openvz -prefix -vserver
|
2011-05-03 02:39:59 +04:00
|
|
|
}
|
|
|
|
|
2011-07-25 04:00:53 +04:00
|
|
|
ZFS="@sbindir@/zfs"
|
|
|
|
ZPOOL="@sbindir@/zpool"
|
2011-08-23 02:58:54 +04:00
|
|
|
ZPOOL_CACHE="@sysconfdir@/zfs/zpool.cache"
|
2011-05-03 02:39:59 +04:00
|
|
|
ZFS_MODULE=zfs
|
|
|
|
|
2011-05-10 23:45:19 +04:00
|
|
|
checksystem() {
|
2011-07-05 01:58:51 +04:00
|
|
|
if [ ! -c /dev/zfs ]; then
|
2011-05-10 23:45:19 +04:00
|
|
|
einfo "Checking if ZFS modules present"
|
2012-04-03 08:21:22 +04:00
|
|
|
if ! modinfo zfs > /dev/null 2>&1 ; then
|
2011-05-10 23:45:19 +04:00
|
|
|
eerror "$ZFS_MODULE not found. Is the ZFS package installed?"
|
|
|
|
return 1
|
|
|
|
fi
|
2011-05-03 02:39:59 +04:00
|
|
|
fi
|
2011-05-10 23:45:19 +04:00
|
|
|
einfo "Checking if zfs userspace tools present"
|
|
|
|
if [ ! -x $ZPOOL ]; then
|
|
|
|
eerror "$ZPOOL binary not found."
|
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
if [ ! -x $ZFS ]; then
|
|
|
|
eerror "$ZFS binary not found."
|
|
|
|
return 1
|
|
|
|
fi
|
2011-05-03 02:39:59 +04:00
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2011-05-10 23:45:19 +04:00
|
|
|
start() {
|
2011-05-03 02:39:59 +04:00
|
|
|
ebegin "Starting ZFS"
|
|
|
|
checksystem || return 1
|
2011-07-01 01:45:33 +04:00
|
|
|
|
|
|
|
# Delay until all required block devices are present.
|
|
|
|
udevadm settle
|
|
|
|
|
2011-05-10 23:45:19 +04:00
|
|
|
if [ ! -c /dev/zfs ]; then
|
|
|
|
modprobe $ZFS_MODULE
|
2011-05-03 02:39:59 +04:00
|
|
|
rv=$?
|
2011-05-10 23:45:19 +04:00
|
|
|
if [ $rv -ne 0 ]; then
|
2011-05-03 02:39:59 +04:00
|
|
|
eerror "Failed to load the $ZFS_MODULE module, check 'dmesg|tail'."
|
|
|
|
eend $rv
|
|
|
|
return $rv
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Import all pools described by the cache file, and then mount
|
|
|
|
# all filesystem based on their properties.
|
2011-07-25 04:00:53 +04:00
|
|
|
if [ -f $ZPOOL_CACHE ]; then
|
2011-05-03 02:39:59 +04:00
|
|
|
einfo "Importing ZFS pools"
|
|
|
|
# as per fedora script, import can fail if all pools are already imported
|
|
|
|
# The check for $rv makes no sense...but someday, it will work right.
|
2011-07-25 04:00:53 +04:00
|
|
|
$ZPOOL import -c $ZPOOL_CACHE -aN 2>/dev/null || true
|
2011-05-03 02:39:59 +04:00
|
|
|
rv=$?
|
2011-05-10 23:45:19 +04:00
|
|
|
if [ $rv -ne 0 ]; then
|
2011-05-03 02:39:59 +04:00
|
|
|
eerror "Failed to import not-yet imported pools."
|
|
|
|
eend $rv
|
|
|
|
return $rv
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
|
|
|
einfo "Mounting ZFS filesystems"
|
|
|
|
$ZFS mount -a
|
|
|
|
rv=$?
|
2011-05-10 23:45:19 +04:00
|
|
|
if [ $rv -ne 0 ]; then
|
2011-05-03 02:39:59 +04:00
|
|
|
eerror "Failed to mount ZFS filesystems."
|
|
|
|
eend $rv
|
|
|
|
return $rv
|
|
|
|
fi
|
|
|
|
|
2011-07-03 04:43:25 +04:00
|
|
|
einfo "Exporting ZFS filesystems"
|
|
|
|
$ZFS share -a
|
|
|
|
rv=$?
|
|
|
|
if [ $rv -ne 0 ]; then
|
|
|
|
eerror "Failed to export ZFS filesystems."
|
|
|
|
eend $rv
|
|
|
|
return $rv
|
|
|
|
fi
|
|
|
|
|
2011-05-03 02:39:59 +04:00
|
|
|
eend 0
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
|
|
|
stop()
|
|
|
|
{
|
|
|
|
ebegin "Unmounting ZFS filesystems"
|
|
|
|
$ZFS umount -a
|
2011-05-11 00:22:35 +04:00
|
|
|
rv=$?
|
2011-05-10 23:45:19 +04:00
|
|
|
if [ $rv -ne 0 ]; then
|
2011-07-05 01:58:51 +04:00
|
|
|
einfo "Some ZFS filesystems not unmounted"
|
2011-05-03 02:39:59 +04:00
|
|
|
fi
|
2011-05-10 23:45:19 +04:00
|
|
|
|
2011-07-05 01:58:51 +04:00
|
|
|
# Don't fail if we couldn't umount everything. /usr might be in use.
|
|
|
|
eend 0
|
|
|
|
return 0
|
2011-05-03 02:39:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
status()
|
|
|
|
{
|
|
|
|
# show pool status and list
|
|
|
|
$ZPOOL status && echo && $ZPOOL list
|
|
|
|
}
|