2011-03-17 22:18:13 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
. /lib/dracut-lib.sh
|
|
|
|
|
2011-07-04 17:25:31 +00:00
|
|
|
ZPOOL_FORCE=""
|
2015-02-07 10:34:22 +00:00
|
|
|
OLDIFS="$IFS"
|
|
|
|
NEWLINE="
|
|
|
|
"
|
2011-07-24 20:53:15 +00:00
|
|
|
|
2011-07-04 17:25:31 +00:00
|
|
|
if getargbool 0 zfs_force -y zfs.force -y zfsforce ; then
|
2011-07-24 20:46:16 +00:00
|
|
|
warn "ZFS: Will force-import pools if necessary."
|
|
|
|
ZPOOL_FORCE="-f"
|
2011-07-04 17:25:31 +00:00
|
|
|
fi
|
|
|
|
|
2015-03-23 16:17:56 +00:00
|
|
|
# Delay until all required block devices are present.
|
|
|
|
udevadm settle
|
|
|
|
|
2011-07-04 17:25:31 +00:00
|
|
|
case "$root" in
|
2011-07-24 20:46:16 +00:00
|
|
|
zfs:*)
|
|
|
|
# We have ZFS modules loaded, so we're able to import pools now.
|
|
|
|
if [ "$root" = "zfs:AUTO" ] ; then
|
|
|
|
# Need to parse bootfs attribute
|
|
|
|
info "ZFS: Attempting to detect root from imported ZFS pools."
|
2011-07-04 17:25:31 +00:00
|
|
|
|
2011-07-24 20:46:16 +00:00
|
|
|
# Might be imported by the kernel module, so try searching before
|
|
|
|
# we import anything.
|
2014-03-20 20:21:34 +00:00
|
|
|
zfsbootfs=`zpool list -H -o bootfs | sed -n '/^-$/ !p' | sed 'q'`
|
2015-02-10 19:12:13 +00:00
|
|
|
if [ $? -ne 0 ] || [ -z "$zfsbootfs" ] || \
|
2011-07-31 04:21:40 +00:00
|
|
|
[ "$zfsbootfs" = "no pools available" ] ; then
|
2011-07-24 20:46:16 +00:00
|
|
|
# Not there, so we need to import everything.
|
|
|
|
info "ZFS: Attempting to import additional pools."
|
|
|
|
zpool import -N -a ${ZPOOL_FORCE}
|
2014-03-20 20:21:34 +00:00
|
|
|
zfsbootfs=`zpool list -H -o bootfs | sed -n '/^-$/ !p' | sed 'q'`
|
2015-02-10 19:12:13 +00:00
|
|
|
if [ $? -ne 0 ] || [ -z "$zfsbootfs" ] || \
|
2011-07-31 04:21:40 +00:00
|
|
|
[ "$zfsbootfs" = "no pools available" ] ; then
|
2011-07-24 20:46:16 +00:00
|
|
|
rootok=0
|
|
|
|
pool=""
|
2011-07-04 17:25:31 +00:00
|
|
|
|
2011-07-24 20:46:16 +00:00
|
|
|
warn "ZFS: No bootfs attribute found in importable pools."
|
2011-07-04 17:25:31 +00:00
|
|
|
|
2011-07-24 20:46:16 +00:00
|
|
|
# Re-export everything since we're not prepared to take
|
|
|
|
# responsibility for them.
|
2015-02-07 10:34:22 +00:00
|
|
|
# Change IFS to allow for blanks in pool names.
|
|
|
|
IFS="$NEWLINE"
|
|
|
|
for fs in `zpool list -H -o name` ; do
|
2011-07-24 20:46:16 +00:00
|
|
|
zpool export "$fs"
|
|
|
|
done
|
2015-02-07 10:34:22 +00:00
|
|
|
IFS="$OLDIFS"
|
2011-07-04 17:25:31 +00:00
|
|
|
|
2011-07-24 20:46:16 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
info "ZFS: Using ${zfsbootfs} as root."
|
|
|
|
else
|
|
|
|
# Should have an explicit pool set, so just import it and we're done.
|
|
|
|
zfsbootfs="${root#zfs:}"
|
|
|
|
pool="${zfsbootfs%%/*}"
|
2015-02-07 10:34:22 +00:00
|
|
|
if ! zpool list -H "$pool" > /dev/null ; then
|
2011-07-24 20:46:16 +00:00
|
|
|
# pool wasn't imported automatically by the kernel module, so
|
|
|
|
# try it manually.
|
|
|
|
info "ZFS: Importing pool ${pool}..."
|
2015-02-07 10:34:22 +00:00
|
|
|
if ! zpool import -N ${ZPOOL_FORCE} "$pool" ; then
|
2011-07-24 20:46:16 +00:00
|
|
|
warn "ZFS: Unable to import pool ${pool}."
|
|
|
|
rootok=0
|
2011-07-04 17:25:31 +00:00
|
|
|
|
2011-07-24 20:46:16 +00:00
|
|
|
return 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
fi
|
2011-07-04 17:25:31 +00:00
|
|
|
|
2011-07-24 20:46:16 +00:00
|
|
|
# Above should have left our rpool imported and pool/dataset in $root.
|
|
|
|
# We need zfsutil for non-legacy mounts and not for legacy mounts.
|
2015-02-07 10:34:22 +00:00
|
|
|
mountpoint=`zfs get -H -o value mountpoint "$zfsbootfs"`
|
2011-07-24 20:46:16 +00:00
|
|
|
if [ "$mountpoint" = "legacy" ] ; then
|
|
|
|
mount -t zfs "$zfsbootfs" "$NEWROOT" && ROOTFS_MOUNTED=yes
|
|
|
|
else
|
|
|
|
mount -o zfsutil -t zfs "$zfsbootfs" "$NEWROOT" && ROOTFS_MOUNTED=yes
|
|
|
|
fi
|
2014-10-06 11:08:33 +00:00
|
|
|
|
|
|
|
need_shutdown
|
2011-07-24 20:46:16 +00:00
|
|
|
;;
|
2011-07-04 17:25:31 +00:00
|
|
|
esac
|