]> git.proxmox.com Git - mirror_zfs-debian.git/blobdiff - dracut/90zfs/mount-zfs.sh.in
Imported Upstream version 0.6.4.2
[mirror_zfs-debian.git] / dracut / 90zfs / mount-zfs.sh.in
index 2d2afd879f99741147cc7bd1a8bc47af8b6817d4..8237d76f2efee9e15bbcc8f3c1d0a8b47f93874e 100755 (executable)
@@ -3,12 +3,18 @@
 . /lib/dracut-lib.sh
 
 ZPOOL_FORCE=""
+OLDIFS="$IFS"
+NEWLINE="
+"
 
 if getargbool 0 zfs_force -y zfs.force -y zfsforce ; then
        warn "ZFS: Will force-import pools if necessary."
        ZPOOL_FORCE="-f"
 fi
 
+# Delay until all required block devices are present.
+udevadm settle
+
 case "$root" in
        zfs:*)
                # We have ZFS modules loaded, so we're able to import pools now.
@@ -18,14 +24,14 @@ case "$root" in
 
                        # Might be imported by the kernel module, so try searching before
                        # we import anything.
-                       zfsbootfs=`zpool list -H -o bootfs | sed -n '/-/ !p' | sed 'q'`
-                       if [ "$?" != "0" ] || [ "$zfsbootfs" = "" ] || \
+                       zfsbootfs=`zpool list -H -o bootfs | sed -n '/^-$/ !p' | sed 'q'`
+                       if [ $? -ne 0 ] || [ -z "$zfsbootfs" ] || \
                                [ "$zfsbootfs" = "no pools available" ] ; then
                                # Not there, so we need to import everything.
                                info "ZFS: Attempting to import additional pools."
                                zpool import -N -a ${ZPOOL_FORCE}
-                               zfsbootfs=`zpool list -H -o bootfs | sed -n '/-/ !p' | sed 'q'`
-                               if [ "$?" != "0" ] || [ "$zfsbootfs" = "" ] || \
+                               zfsbootfs=`zpool list -H -o bootfs | sed -n '/^-$/ !p' | sed 'q'`
+                               if [ $? -ne 0 ] || [ -z "$zfsbootfs" ] || \
                                        [ "$zfsbootfs" = "no pools available" ] ; then
                                        rootok=0
                                        pool=""
@@ -34,9 +40,12 @@ case "$root" in
 
                                        # Re-export everything since we're not prepared to take
                                        # responsibility for them.
-                                       zpool list -H | while read fs rest ; do
+                                       # Change IFS to allow for blanks in pool names.
+                                       IFS="$NEWLINE"
+                                       for fs in `zpool list -H -o name` ; do
                                                zpool export "$fs"
                                        done
+                                       IFS="$OLDIFS"
 
                                        return 1
                                fi
@@ -46,11 +55,11 @@ case "$root" in
                        # Should have an explicit pool set, so just import it and we're done.
                        zfsbootfs="${root#zfs:}"
                        pool="${zfsbootfs%%/*}"
-                       if ! zpool list -H $pool > /dev/null ; then
+                       if ! zpool list -H "$pool" > /dev/null ; then
                                # pool wasn't imported automatically by the kernel module, so
                                # try it manually.
                                info "ZFS: Importing pool ${pool}..."
-                               if ! zpool import -N ${ZPOOL_FORCE} $pool ; then
+                               if ! zpool import -N ${ZPOOL_FORCE} "$pool" ; then
                                        warn "ZFS: Unable to import pool ${pool}."
                                        rootok=0
 
@@ -61,11 +70,13 @@ case "$root" in
 
                # Above should have left our rpool imported and pool/dataset in $root.
                # We need zfsutil for non-legacy mounts and not for legacy mounts.
-               mountpoint=`zfs get -H -o value mountpoint $zfsbootfs`
+               mountpoint=`zfs get -H -o value mountpoint "$zfsbootfs"`
                if [ "$mountpoint" = "legacy" ] ; then
                        mount -t zfs "$zfsbootfs" "$NEWROOT" && ROOTFS_MOUNTED=yes
                else
                        mount -o zfsutil -t zfs "$zfsbootfs" "$NEWROOT" && ROOTFS_MOUNTED=yes
                fi
+
+               need_shutdown
                ;;
 esac