Improve ZFS diagnostics, import and mounting
authorRichard Yao <ryao@cs.stonybrook.edu>
Mon, 30 Apr 2012 17:34:01 +0000 (13:34 -0400)
committerRichard Yao <ryao@cs.stonybrook.edu>
Mon, 30 Apr 2012 20:39:13 +0000 (16:39 -0400)
Make ZFS only import the specified pool
Set zfsutil when mounting non-legacy rootfs
Check for /sbin/zpool in addition to /sbin/zfs
Print information messages when ZFS pools are imported
Prompt user when mounting a ZFS filesystem without ZFS support
Verify that <dataset> in real_root=ZFS=<dataset> is a filesystem

defaults/initrd.scripts
defaults/linuxrc

index 02843c57becc5d13f66b0f9a7af83add56aaa342..a7d88e42e043455e092d6e6fa399443a1fbd6de1 100755 (executable)
@@ -654,11 +654,29 @@ startVolumes() {
        
        if [ "${USE_ZFS}" = '1' ]
        then
-               if [ -e '/sbin/zpool' ]
+               if [ -z "${ZFS_POOL}" ];
                then
-                       /sbin/zpool import -N -a ${ZPOOL_FORCE}
+                       good_msg "Importing ZFS pools"
+
+                       /sbin/zpool import -N -a "${ZPOOL_FORCE}"
+
+                       if [ "$?" = '0' ]
+                       then
+                               good_msg "Importing ZFS pools succeeded"
+                       else
+                               bad_msg "Imported ZFS pools failed"
+                       fi
                else
-                       bad_msg "zpool not found: skipping ZFS pool import!"
+                       good_msg "Importing ZFS pool ${ZFS_POOL}"
+
+                       /sbin/zpool import -N "${ZPOOL_FORCE}" "${ZFS_POOL}"
+
+                       if [ "$?" = '0' ]
+                       then
+                               good_msg "Importing ${ZFS_POOL} succeeded"
+                       else
+                               bad_msg "Importing ${ZFS_POOL} failed"
+                       fi
                fi
        fi
 }
index f6c0de52c6fa09dd1797b88adfec9cc5765395b3..6103e23e8e0aa7d2a9bb0745de8f6943cdf28cd1 100755 (executable)
@@ -251,6 +251,11 @@ fi
 # Set variables based on the value of REAL_ROOT
 case "${REAL_ROOT}" in
        ZFS*)
+               ZFS_POOL=${REAL_ROOT#*=}
+               ZFS_POOL=${ZFS_POOL%%/*}
+               USE_ZFS=1
+       ;;
+       ZFS)
                USE_ZFS=1
        ;;
 esac
@@ -258,12 +263,15 @@ esac
 # Verify that it is safe to use ZFS
 if [ "USE_ZFS" = "1" ]
 then
-       if [ -x /sbin/zfs ]
+       if [ -x /sbin/zfs -a -x /sbin/zpool ]
        then
                MY_HWOPTS="${MY_HWOPTS} zfs"
        else
-               bad_msg 'zfs binary not found: aborting use of zfs!'
                USE_ZFS=0
+
+               [ -x /sbin/zfs ] || bad_msg '/sbin/zfs not found!'
+               [ -x /sbin/zpool ] || bad_msg '/sbin/zpool not found!'
+               bad_msg 'Aborting use of zfs!'
        fi
 fi
 
@@ -486,16 +494,24 @@ do
                                fi
                                ;;
                        ZFS*)
+                               if [ "${USE_ZFS}" = '0' ]; then
+                                       prompt_user "REAL_ROOT" "root block device"
+                                       continue
+                               fi
+                                       
                                ROOT_DEV="${REAL_ROOT#*=}"
                                if [ "${ROOT_DEV}" != 'ZFS' ] 
                                then
-                                       zfs get type ${ROOT_DEV} > /dev/null
-
-                                       if [ "$?" = '0' ]
+                                       if [ "$(zfs get type -o value -H ${ROOT_DEV})" = 'filesystem' ]
                                        then
                                                got_good_root=1;
                                                REAL_ROOT=${ROOT_DEV}
                                                ROOTFSTYPE=zfs
+                                       else
+                                               bad_msg "${ROOT_DEV} is not a filesystem"
+                                               prompt_user "REAL_ROOT" "root block device"
+                                               got_good_root=0
+                                               continue
                                        fi
                                else
                                        BOOTFS=$(/sbin/zpool list -H -o bootfs)
@@ -563,7 +579,12 @@ do
 
                if [ "${ROOTFSTYPE}" = 'zfs' ]
                then
-                       MOUNT_STATE=rw
+                       if [ "zfs get -H -o value mountpoint ${REAL_ROOT}" = 'legacy' ]
+                       then
+                               MOUNT_STATE=rw
+                       else
+                               MOUNT_STATE=rw,zfsutil
+                       fi
                else
                        MOUNT_STATE=ro
                fi