--- zfs.orig 2016-04-19 00:56:11.496000000 -0500 +++ zfs 2016-04-19 01:14:38.907759621 -0500 @@ -8,7 +8,6 @@ then ZFS_HEALTH=$(zpool list -H -o health "$ZFS_RPOOL" 2>/dev/null) fi - zpool export "$ZFS_RPOOL" >/dev/null 2>&1 } mountroot() @@ -31,32 +30,54 @@ delay=${ROOTDELAY:-0} + # Try to import the pool read-only. + zfs_test_import + if [ "$delay" -gt 0 ] then - # Try to import the pool read-only. If it does not import with - # the ONLINE status, wait and try again. The pool could be - # DEGRADED because a drive is really missing, or it might just - # be slow to be detected. - zfs_test_import + # If it does not import with the ONLINE status, wait and try + # again. The pool could be DEGRADED because a drive is really + # missing, or it might just be slow to be detected. retry_nr=0 while [ "$retry_nr" -lt "$delay" ] && [ "$ZFS_HEALTH" != "ONLINE" ] do [ "$quiet" != "y" ] && log_begin_msg "Retrying ZFS read-only import" + zpool export "$ZFS_RPOOL" >/dev/null 2>&1 /bin/sleep 1 zfs_test_import retry_nr=$(( $retry_nr + 1 )) [ "$quiet" != "y" ] && log_end_msg done unset retry_nr - unset ZFS_HEALTH fi unset delay # At this point, the pool either imported cleanly, or we ran out of the - # allowed time (rootdelay). Perform the read-write import. - ZFS_STDERR=$(zpool import -N "$ZFS_RPOOL" 2>&1) - ZFS_ERROR=$? + # allowed time (rootdelay). + if [ "$ZFS_HEALTH" = "ONLINE" ] + then + # It imported cleanly. Check for a zpool.cache file. + if mount -t zfs -o zfsutil,ro "$ZFS_BOOTFS" "$rootmnt" >/dev/null 2>&1 + then + if [ -e "$rootmnt/etc/zfs/zpool.cache" ] + then + mkdir -p /etc/zfs + cp "$rootmnt/etc/zfs/zpool.cache" /etc/zfs + fi + umount "$rootmnt" + fi + fi + unset ZFS_HEALTH + zpool export "$ZFS_RPOOL" >/dev/null 2>&1 + # Try the read-write import. + if [ -e /etc/zfs/zpool.cache ] + then + ZFS_STDERR=$(zpool import -c /etc/zfs/zpool.cache -N "$ZFS_RPOOL" 2>&1) + else + ZFS_STDERR=$(zpool import -N "$ZFS_RPOOL" 2>&1) + fi + ZFS_ERROR=$? if [ "$ZFS_ERROR" -ne 0 ] then panic "Command: zpool import -N $ZFS_RPOOL