aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/openzfs/contrib/initramfs/scripts/zfs
diff options
context:
space:
mode:
Diffstat (limited to 'sys/contrib/openzfs/contrib/initramfs/scripts/zfs')
-rw-r--r--sys/contrib/openzfs/contrib/initramfs/scripts/zfs110
1 files changed, 68 insertions, 42 deletions
diff --git a/sys/contrib/openzfs/contrib/initramfs/scripts/zfs b/sys/contrib/openzfs/contrib/initramfs/scripts/zfs
index ccb42ce103b9..0a2bd2efda7a 100644
--- a/sys/contrib/openzfs/contrib/initramfs/scripts/zfs
+++ b/sys/contrib/openzfs/contrib/initramfs/scripts/zfs
@@ -194,7 +194,7 @@ import_pool()
# Verify that the pool isn't already imported
# Make as sure as we can to not require '-f' to import.
- "${ZPOOL}" get name,guid -o value -H 2>/dev/null | grep -Fxq "$pool" && return 0
+ "${ZPOOL}" get -H -o value name,guid 2>/dev/null | grep -Fxq "$pool" && return 0
# For backwards compatibility, make sure that ZPOOL_IMPORT_PATH is set
# to something we can use later with the real import(s). We want to
@@ -272,30 +272,46 @@ import_pool()
# with more logging etc.
load_module_initrd()
{
- [ -n "$ROOTDELAY" ] && ZFS_INITRD_PRE_MOUNTROOT_SLEEP="$ROOTDELAY"
+ ZFS_INITRD_PRE_MOUNTROOT_SLEEP=${ROOTDELAY:-0}
- if [ "$ZFS_INITRD_PRE_MOUNTROOT_SLEEP" -gt 0 ] 2>/dev/null
- then
- if [ "$quiet" != "y" ]; then
- zfs_log_begin_msg "Sleeping for" \
- "$ZFS_INITRD_PRE_MOUNTROOT_SLEEP seconds..."
- fi
- sleep "$ZFS_INITRD_PRE_MOUNTROOT_SLEEP"
- [ "$quiet" != "y" ] && zfs_log_end_msg
+ if [ "$ZFS_INITRD_PRE_MOUNTROOT_SLEEP" -gt 0 ]; then
+ [ "$quiet" != "y" ] && zfs_log_begin_msg "Delaying for up to '${ZFS_INITRD_PRE_MOUNTROOT_SLEEP}' seconds."
fi
- # Wait for all of the /dev/{hd,sd}[a-z] device nodes to appear.
- if command -v wait_for_udev > /dev/null 2>&1 ; then
- wait_for_udev 10
- elif command -v wait_for_dev > /dev/null 2>&1 ; then
- wait_for_dev
- fi
+ START=$(/bin/date -u +%s)
+ END=$((START+ZFS_INITRD_PRE_MOUNTROOT_SLEEP))
+ while true; do
+
+ # Wait for all of the /dev/{hd,sd}[a-z] device nodes to appear.
+ if command -v wait_for_udev > /dev/null 2>&1 ; then
+ wait_for_udev 10
+ elif command -v wait_for_dev > /dev/null 2>&1 ; then
+ wait_for_dev
+ fi
+
+ #
+ # zpool import refuse to import without a valid
+ # /proc/self/mounts
+ #
+ [ ! -f /proc/self/mounts ] && mount proc /proc
+
+ # Load the module
+ if load_module "zfs"; then
+ ret=0
+ break
+ else
+ ret=1
+ fi
- # zpool import refuse to import without a valid /proc/self/mounts
- [ ! -f /proc/self/mounts ] && mount proc /proc
+ [ "$(/bin/date -u +%s)" -gt "$END" ] && break
+ sleep 1
- # Load the module
- load_module "zfs" || return 1
+ done
+ if [ "$ZFS_INITRD_PRE_MOUNTROOT_SLEEP" -gt 0 ]; then
+ [ "$quiet" != "y" ] && zfs_log_end_msg
+ fi
+
+ [ "$ret" -ne 0 ] && return 1
if [ "$ZFS_INITRD_POST_MODPROBE_SLEEP" -gt 0 ] 2>/dev/null
then
@@ -333,25 +349,24 @@ mount_fs()
# Can't use the mountpoint property. Might be one of our
# clones. Check the 'org.zol:mountpoint' property set in
# clone_snap() if that's usable.
- mountpoint=$(get_fs_value "$fs" org.zol:mountpoint)
- if [ "$mountpoint" = "legacy" ] ||
- [ "$mountpoint" = "none" ] ||
- [ "$mountpoint" = "-" ]
+ mountpoint1=$(get_fs_value "$fs" org.zol:mountpoint)
+ if [ "$mountpoint1" = "legacy" ] ||
+ [ "$mountpoint1" = "none" ] ||
+ [ "$mountpoint1" = "-" ]
then
if [ "$fs" != "${ZFS_BOOTFS}" ]; then
# We don't have a proper mountpoint and this
# isn't the root fs.
return 0
- else
- # Last hail-mary: Hope 'rootmnt' is set!
- mountpoint=""
fi
- fi
-
- # If it's not a legacy filesystem, it can only be a
- # native one...
- if [ "$mountpoint" = "legacy" ]; then
- ZFS_CMD="mount -t zfs"
+ # Don't use mount.zfs -o zfsutils for legacy mountpoint
+ if [ "$mountpoint" = "legacy" ]; then
+ ZFS_CMD="mount -t zfs"
+ fi
+ # Last hail-mary: Hope 'rootmnt' is set!
+ mountpoint=""
+ else
+ mountpoint="$mountpoint1"
fi
fi
@@ -405,6 +420,16 @@ decrypt_fs()
# Continue only if the key needs to be loaded
[ "$KEYSTATUS" = "unavailable" ] || return 0
+ # Try extensions first
+ for f in "/etc/zfs/initramfs-tools-load-key" "/etc/zfs/initramfs-tools-load-key.d/"*; do
+ [ -r "$f" ] || continue
+ (. "$f") && {
+ # Successful return and actually-loaded key: we're done
+ KEYSTATUS="$(get_fs_value "${ENCRYPTIONROOT}" keystatus)"
+ [ "$KEYSTATUS" = "unavailable" ] || return 0
+ }
+ done
+
# Do not prompt if key is stored noninteractively,
if ! [ "${KEYLOCATION}" = "prompt" ]; then
$ZFS load-key "${ENCRYPTIONROOT}"
@@ -421,7 +446,7 @@ decrypt_fs()
elif [ -e /run/systemd/system ]; then
echo "systemd-ask-password" > /run/zfs_console_askpwd_cmd
for _ in 1 2 3; do
- systemd-ask-password "Encrypted ZFS password for ${ENCRYPTIONROOT}" --no-tty | \
+ systemd-ask-password --no-tty "Encrypted ZFS password for ${ENCRYPTIONROOT}" | \
$ZFS load-key "${ENCRYPTIONROOT}" && break
done
@@ -505,7 +530,7 @@ clone_snap()
echo "Error: $ZFS_ERROR"
echo ""
echo "Failed to clone snapshot."
- echo "Make sure that the any problems are corrected and then make sure"
+ echo "Make sure that any problems are corrected and then make sure"
echo "that the dataset '$destfs' exists and is bootable."
shell
else
@@ -596,7 +621,7 @@ setup_snapshot_booting()
retval=0
# Make sure that the snapshot specified actually exists.
- if [ ! "$(get_fs_value "${snap}" type)" ]
+ if [ -z "$(get_fs_value "${snap}" type)" ]
then
# Snapshot does not exist (...@<null> ?)
# ask the user for a snapshot to use.
@@ -613,7 +638,8 @@ setup_snapshot_booting()
then
# If the destination dataset for the clone
# already exists, destroy it. Recursively
- if [ "$(get_fs_value "${rootfs}_${snapname}" type)" ]; then
+ if [ -n "$(get_fs_value "${rootfs}_${snapname}" type)" ]
+ then
filesystems=$("${ZFS}" list -oname -tfilesystem -H \
-r -Sname "${ZFS_BOOTFS}")
for fs in $filesystems; do
@@ -639,8 +665,8 @@ setup_snapshot_booting()
# rpool/ROOT/debian/boot@snap2 => rpool/ROOT/debian_snap2/boot
# rpool/ROOT/debian/usr@snap2 => rpool/ROOT/debian_snap2/usr
# rpool/ROOT/debian/var@snap2 => rpool/ROOT/debian_snap2/var
- subfs="${s##$rootfs}"
- subfs="${subfs%%@$snapname}"
+ subfs="${s##"$rootfs"}"
+ subfs="${subfs%%@"$snapname"}"
destfs="${rootfs}_${snapname}" # base fs.
[ -n "$subfs" ] && destfs="${destfs}$subfs" # + sub fs.
@@ -848,7 +874,7 @@ mountroot()
done
IFS="$OLD_IFS"
- [ "$quiet" != "y" ] && zfs_log_end_msg $ZFS_ERROR
+ [ "$quiet" != "y" ] && zfs_log_end_msg "$ZFS_ERROR"
else
# No auto - use value from the command line option.
@@ -887,12 +913,12 @@ mountroot()
fi
# In case the pool was specified as guid, resolve guid to name
- pool="$("${ZPOOL}" get name,guid -o name,value -H | \
+ pool="$("${ZPOOL}" get -H -o name,value name,guid | \
awk -v pool="${ZFS_RPOOL}" '$2 == pool { print $1 }')"
if [ -n "$pool" ]; then
# If $ZFS_BOOTFS contains guid, replace the guid portion with $pool
ZFS_BOOTFS=$(echo "$ZFS_BOOTFS" | \
- sed -e "s/$("${ZPOOL}" get guid -o value "$pool" -H)/$pool/g")
+ sed -e "s/$("${ZPOOL}" get -H -o value guid "$pool")/$pool/g")
ZFS_RPOOL="${pool}"
fi