ZPOOL_FORCE=""
ZPOOL_IMPORT_FLAGS=""
zfs_get_bootfs () {
for zfs_dataset in $(/usr/bin/zpool list -H -o bootfs); do
case ${zfs_dataset} in
"" | "-")
# skip this line/dataset
;;
"no pools available")
return 1
;;
*)
ZFS_DATASET=${zfs_dataset}
return 0
;;
esac
done
return 1
}
zfs_mount_handler () {
local node=$1
if [ "$ZFS_DATASET" = "bootfs" ] ; then
if ! zfs_get_bootfs ; then
# Lets import everything and try again
/usr/bin/zpool import $ZPOOL_IMPORT_FLAGS -N -a $ZPOOL_FORCE
if ! zfs_get_bootfs ; then
echo "ZFS: Cannot find bootfs."
return 1
fi
fi
fi
local pool="${ZFS_DATASET%%/*}"
local rwopt_exp=${rwopt:-ro}
if ! "/usr/bin/zpool" list -H $pool 2>&1 > /dev/null ; then
if [ "$rwopt_exp" != "rw" ]; then
msg "ZFS: Importing pool $pool readonly."
ZPOOL_IMPORT_FLAGS="$ZPOOL_IMPORT_FLAGS -o readonly=on"
else
msg "ZFS: Importing pool $pool."
fi
if ! "/usr/bin/zpool" import $ZPOOL_IMPORT_FLAGS -N $pool $ZPOOL_FORCE ; then
echo "ZFS: Unable to import pool $pool. Sleeping for 10 seconds and then tying again."
sleep 10
if ! "/usr/bin/zpool" import -d /dev -N $pool -f ; then
echo "ZFS: Unable to import pool $pool. Sleeping for 60 seconds and then trying yet again."
sleep 60
if ! "/usr/bin/zpool" import -d /dev -N $pool -f ; then
echo "ZFS: Unable to import pool $pool, even after waiting a good long time for devices to show up."
return 1
fi
fi
fi
fi
local mountpoint=$("/usr/bin/zfs" get -H -o value mountpoint $ZFS_DATASET)
if [ "$mountpoint" = "legacy" ] ; then
mount -t zfs -o ${rwopt_exp} "$ZFS_DATASET" "$node"
else
mount -o zfsutil,${rwopt_exp} -t zfs "$ZFS_DATASET" "$node"
fi
}
run_hook() {
# Force import the pools, useful if the pool has not properly been exported
# using 'zpool export '
[[ $zfs_force == 1 ]] && ZPOOL_FORCE='-f'
[[ "$zfs_import_dir" != "" ]] && ZPOOL_IMPORT_FLAGS="$ZPOOL_IMPORT_FLAGS -d $zfs_import_dir"
if [ "$root" = 'zfs' ]; then
mount_handler='zfs_mount_handler'
fi
case $zfs in
auto|bootfs)
ZFS_DATASET='bootfs'
mount_handler="zfs_mount_handler"
;;
*)
ZFS_DATASET=$zfs
mount_handler="zfs_mount_handler"
;;
esac
if [ ! -f "/etc/hostid" ] ; then
echo "ZFS: No hostid found on kernel command line or /etc/hostid. ZFS pools may not import correctly."
fi
# Allow up to 10 seconds for zfs device to show up
for i in 1 2 3 4 5 6 7 8 9 10; do
[ -c "/dev/zfs" ] && break
sleep 1
done
}
Next, we run "mkinitcpio -p linux-lts", exit the chroot, "zpool export root_pool", reboot, and we see that the first zpool import attempt still fails. However, we are then into the code we added, which waits ten seconds and tries zpool importing again. This second attempt succeeds.July 2009 August 2009 September 2009 October 2009 November 2009 December 2009 January 2010 September 2010 December 2010 January 2011 February 2011 April 2011 June 2011 August 2011 February 2012 June 2012 July 2012 August 2012 October 2012 November 2012 January 2014 April 2014 June 2014 August 2014 September 2014 October 2014 January 2015 March 2015 April 2015 June 2015 November 2015 December 2015 January 2016 June 2016 August 2016 January 2017 March 2017 April 2018 April 2019 June 2019 January 2020
Subscribe to Posts [Atom]
Post a Comment