-if [ "$rootfs" = "zfs" ]; then
- zfsrootfs=`echo "$root" | sed 's|^zfs:||'`
- zfspool=`echo "$zfsrootfs" | sed 's|/.*||g'`
- zpool import -N "$zfspool"
- mount -o zfsutil -t "$rootfs" "$zfsrootfs" "$NEWROOT"
- if [ "$?" = "0" ]
- then
- ROOTFS_MOUNTED=yes
+ZPOOL_FORCE=""
+if getargbool 0 zfs_force -y zfs.force -y zfsforce ; then
+ warn "ZFS: Will force-import pools if necessary."
+ ZPOOL_FORCE="-f"
+fi
+
+case "$root" in
+ 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."
+
+ # Might be imported by the kernel module, so try searching before
+ # we import anything.
+ zfsbootfs=`zpool list -H -o bootfs | sed 'q'`
+ if [ "$zfsbootfs" = "" ] ; 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 'q'`
+ if [ "$zfsbootfs" = "" ] ; then
+ rootok=0
+ pool=""
+
+ warn "ZFS: No bootfs attribute found in importable pools."
+
+ # Re-export everything since we're not prepared to take
+ # responsibility for them.
+ zpool list -H | while read fs rest ; do
+ zpool export "$fs"
+ done
+
+ return 1
+ fi
+ fi
+ info "ZFS: Using ${zfsbootfs} as root."