Shell script good practices changes.

It's considered good practice to:
1) Wrap the variable name in `{}`.
   As in `${variable}` instead of `$variable`.
2) Put variables in `"`.

Also some minor error message tuning.

Reviewed by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: Rob Norris <robn@despairlabs.com>
Signed-off-by: Turbo Fredriksson <turbo@bayour.com>
Closes #18000
This commit is contained in:
Turbo Fredriksson 2025-12-01 18:15:04 +00:00 committed by Brian Behlendorf
parent 61ab032ae0
commit d3b447de4e

View File

@ -32,18 +32,18 @@ pre_mountroot()
then then
if [ -f "/scripts/local-top" ] || [ -d "/scripts/local-top" ] if [ -f "/scripts/local-top" ] || [ -d "/scripts/local-top" ]
then then
[ "$quiet" != "y" ] && \ [ "${quiet}" != "y" ] && \
zfs_log_begin_msg "Running /scripts/local-top" zfs_log_begin_msg "Running /scripts/local-top"
run_scripts /scripts/local-top run_scripts /scripts/local-top
[ "$quiet" != "y" ] && zfs_log_end_msg [ "${quiet}" != "y" ] && zfs_log_end_msg
fi fi
if [ -f "/scripts/local-premount" ] || [ -d "/scripts/local-premount" ] if [ -f "/scripts/local-premount" ] || [ -d "/scripts/local-premount" ]
then then
[ "$quiet" != "y" ] && \ [ "${quiet}" != "y" ] && \
zfs_log_begin_msg "Running /scripts/local-premount" zfs_log_begin_msg "Running /scripts/local-premount"
run_scripts /scripts/local-premount run_scripts /scripts/local-premount
[ "$quiet" != "y" ] && zfs_log_end_msg [ "${quiet}" != "y" ] && zfs_log_end_msg
fi fi
fi fi
} }
@ -60,10 +60,10 @@ disable_plymouth()
# Get a ZFS filesystem property value. # Get a ZFS filesystem property value.
get_fs_value() get_fs_value()
{ {
get_fs="$1" get_fs="${1}"
get_value=$2 get_value="${2}"
"${ZFS}" get -H -ovalue "$get_value" "$get_fs" 2> /dev/null "${ZFS}" get -H -ovalue "${get_value}" "${get_fs}" 2> /dev/null
} }
# Find the 'bootfs' property on pool $1. # Find the 'bootfs' property on pool $1.
@ -71,7 +71,7 @@ get_fs_value()
# pool by exporting it again. # pool by exporting it again.
find_rootfs() find_rootfs()
{ {
find_rootfs_pool="$1" find_rootfs_pool="${1}"
# If 'POOL_IMPORTED' isn't set, no pool imported and therefore # If 'POOL_IMPORTED' isn't set, no pool imported and therefore
# we won't be able to find a root fs. # we won't be able to find a root fs.
@ -85,7 +85,7 @@ find_rootfs()
# Not set, try to find it in the 'bootfs' property of the pool. # Not set, try to find it in the 'bootfs' property of the pool.
# NOTE: zpool does not support 'get -H -ovalue bootfs'... # NOTE: zpool does not support 'get -H -ovalue bootfs'...
ZFS_BOOTFS=$("${ZPOOL}" list -H -obootfs "$find_rootfs_pool") ZFS_BOOTFS=$("${ZPOOL}" list -H -obootfs "${find_rootfs_pool}")
# Make sure it's not '-' and that it starts with /. # Make sure it's not '-' and that it starts with /.
if [ "${ZFS_BOOTFS}" != "-" ] && \ if [ "${ZFS_BOOTFS}" != "-" ] && \
@ -97,7 +97,7 @@ find_rootfs()
fi fi
# Not boot fs here, export it and later try again.. # Not boot fs here, export it and later try again..
"${ZPOOL}" export "$find_rootfs_pool" "${ZPOOL}" export "${find_rootfs_pool}"
POOL_IMPORTED= POOL_IMPORTED=
ZFS_BOOTFS= ZFS_BOOTFS=
return 1 return 1
@ -106,7 +106,7 @@ find_rootfs()
# Support function to get a list of all pools, separated with ';' # Support function to get a list of all pools, separated with ';'
find_pools() find_pools()
{ {
find_pools=$("$@" 2> /dev/null | \ find_pools=$("${@}" 2> /dev/null | \
sed -Ee '/pool:|^[a-zA-Z0-9]/!d' -e 's@.*: @@' | \ sed -Ee '/pool:|^[a-zA-Z0-9]/!d' -e 's@.*: @@' | \
tr '\n' ';') tr '\n' ';')
@ -117,98 +117,98 @@ find_pools()
get_pools() get_pools()
{ {
if [ -n "${ZFS_POOL_IMPORT}" ]; then if [ -n "${ZFS_POOL_IMPORT}" ]; then
echo "$ZFS_POOL_IMPORT" echo "${ZFS_POOL_IMPORT}"
return 0 return 0
fi fi
# Get the base list of available pools. # Get the base list of available pools.
available_pools=$(find_pools "$ZPOOL" import) available_pools="$(find_pools "${ZPOOL}" import)"
# Just in case - seen it happen (that a pool isn't visible/found # Just in case - seen it happen (that a pool isn't visible/found
# with a simple "zpool import" but only when using the "-d" # with a simple "zpool import" but only when using the "-d"
# option or setting ZPOOL_IMPORT_PATH). # option or setting ZPOOL_IMPORT_PATH).
if [ -d "/dev/disk/by-id" ] if [ -d "/dev/disk/by-id" ]
then then
npools=$(find_pools "$ZPOOL" import -d /dev/disk/by-id) npools="$(find_pools "${ZPOOL}" import -d /dev/disk/by-id)"
if [ -n "$npools" ] if [ -n "${npools}" ]
then then
# Because we have found extra pool(s) here, which wasn't # Because we have found extra pool(s) here, which wasn't
# found 'normally', we need to force USE_DISK_BY_ID to # found 'normally', we need to force USE_DISK_BY_ID to
# make sure we're able to actually import it/them later. # make sure we're able to actually import it/them later.
USE_DISK_BY_ID='yes' USE_DISK_BY_ID='yes'
if [ -n "$available_pools" ] if [ -n "${available_pools}" ]
then then
# Filter out duplicates (pools found with the simple # Filter out duplicates (pools found with the simple
# "zpool import" but which is also found with the # "zpool import" but which is also found with the
# "zpool import -d ..."). # "zpool import -d ...").
npools=$(echo "$npools" | sed "s,$available_pools,,") npools="$(echo "${npools}" | sed "s,${available_pools},,")"
# Add the list to the existing list of # Add the list to the existing list of
# available pools # available pools
available_pools="$available_pools;$npools" available_pools="${available_pools};${npools}"
else else
available_pools="$npools" available_pools="${npools}"
fi fi
fi fi
fi fi
# Filter out any exceptions... # Filter out any exceptions...
if [ -n "$ZFS_POOL_EXCEPTIONS" ] if [ -n "${ZFS_POOL_EXCEPTIONS}" ]
then then
found="" found=""
apools="" apools=""
OLD_IFS="$IFS" ; IFS=";" OLD_IFS="${IFS}" ; IFS=";"
for pool in $available_pools for pool in ${available_pools}
do do
for exception in $ZFS_POOL_EXCEPTIONS for exception in ${ZFS_POOL_EXCEPTIONS}
do do
[ "$pool" = "$exception" ] && continue 2 [ "${pool}" = "${exception}" ] && continue 2
found="$pool" found="${pool}"
done done
if [ -n "$found" ] if [ -n "${found}" ]
then then
if [ -n "$apools" ] if [ -n "${apools}" ]
then then
apools="$apools;$pool" apools="${apools};${pool}"
else else
apools="$pool" apools="${pool}"
fi fi
fi fi
done done
IFS="$OLD_IFS" IFS="${OLD_IFS}"
available_pools="$apools" available_pools="${apools}"
fi fi
# Return list of available pools. # Return list of available pools.
echo "$available_pools" echo "${available_pools}"
} }
# Import given pool $1 # Import given pool $1
import_pool() import_pool()
{ {
import_pool="$1" import_pool="${1}"
# Verify that the pool isn't already imported # Verify that the pool isn't already imported
# Make as sure as we can to not require '-f' to import. # Make as sure as we can to not require '-f' to import.
"${ZPOOL}" get -H -o value name,guid 2>/dev/null | grep -Fxq "$import_pool" && return 0 "${ZPOOL}" get -H -o value name,guid 2>/dev/null | grep -Fxq "${import_pool}" && return 0
# For backwards compatibility, make sure that ZPOOL_IMPORT_PATH is set # 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 # to something we can use later with the real import(s). We want to
# make sure we find all by* dirs, BUT by-vdev should be first (if it # make sure we find all by* dirs, BUT by-vdev should be first (if it
# exists). # exists).
if [ -n "$USE_DISK_BY_ID" ] && [ -z "$ZPOOL_IMPORT_PATH" ] if [ -n "${USE_DISK_BY_ID}" ] && [ -z "${ZPOOL_IMPORT_PATH}" ]
then then
dirs="$(for dir in /dev/disk/by-* dirs="$(for dir in /dev/disk/by-*
do do
# Ignore by-vdev here - we want it first! # Ignore by-vdev here - we want it first!
echo "$dir" | grep -q /by-vdev && continue echo "${dir}" | grep -q /by-vdev && continue
[ ! -d "$dir" ] && continue [ ! -d "${dir}" ] && continue
printf "%s" "$dir:" printf "%s" "${dir}:"
done | sed 's,:$,,g')" done | sed 's,:$,,g')"
if [ -d "/dev/disk/by-vdev" ] if [ -d "/dev/disk/by-vdev" ]
@ -218,50 +218,50 @@ import_pool()
fi fi
# ... and /dev at the very end, just for good measure. # ... and /dev at the very end, just for good measure.
ZPOOL_IMPORT_PATH="$ZPOOL_IMPORT_PATH$dirs:/dev" ZPOOL_IMPORT_PATH="${ZPOOL_IMPORT_PATH}${dirs}:/dev"
fi fi
# Needs to be exported for "zpool" to catch it. # Needs to be exported for "zpool" to catch it.
[ -n "$ZPOOL_IMPORT_PATH" ] && export ZPOOL_IMPORT_PATH [ -n "${ZPOOL_IMPORT_PATH}" ] && export ZPOOL_IMPORT_PATH
[ "$quiet" != "y" ] && zfs_log_begin_msg \ [ "${quiet}" != "y" ] && zfs_log_begin_msg \
"Importing pool '${import_pool}' using defaults" "Importing pool '${import_pool}' using defaults"
ZFS_CMD="${ZPOOL} import -N ${ZPOOL_FORCE} ${ZPOOL_IMPORT_OPTS}" ZFS_CMD="${ZPOOL} import -N ${ZPOOL_FORCE} ${ZPOOL_IMPORT_OPTS}"
ZFS_STDERR="$($ZFS_CMD "$import_pool" 2>&1)" ZFS_STDERR="$(${ZFS_CMD} "${import_pool}" 2>&1)"
ZFS_ERROR="$?" ZFS_ERROR="${?}"
if [ "${ZFS_ERROR}" != 0 ] if [ "${ZFS_ERROR}" != 0 ]
then then
[ "$quiet" != "y" ] && zfs_log_failure_msg "${ZFS_ERROR}" [ "${quiet}" != "y" ] && zfs_log_failure_msg "${ZFS_ERROR}"
if [ -f "${ZPOOL_CACHE}" ] if [ -f "${ZPOOL_CACHE}" ]
then then
[ "$quiet" != "y" ] && zfs_log_begin_msg \ [ "${quiet}" != "y" ] && zfs_log_begin_msg \
"Importing pool '${import_pool}' using cachefile." "Importing pool '${import_pool}' using cachefile."
ZFS_CMD="${ZPOOL} import -c ${ZPOOL_CACHE} -N ${ZPOOL_FORCE} ${ZPOOL_IMPORT_OPTS}" ZFS_CMD="${ZPOOL} import -c ${ZPOOL_CACHE} -N ${ZPOOL_FORCE} ${ZPOOL_IMPORT_OPTS}"
ZFS_STDERR="$($ZFS_CMD "$import_pool" 2>&1)" ZFS_STDERR="$(${ZFS_CMD} "${import_pool}" 2>&1)"
ZFS_ERROR="$?" ZFS_ERROR="${?}"
fi fi
if [ "${ZFS_ERROR}" != 0 ] if [ "${ZFS_ERROR}" != 0 ]
then then
[ "$quiet" != "y" ] && zfs_log_failure_msg "${ZFS_ERROR}" [ "${quiet}" != "y" ] && zfs_log_failure_msg "${ZFS_ERROR}"
disable_plymouth disable_plymouth
echo "" echo ""
echo "Command: ${ZFS_CMD} '$import_pool'" echo "Command: ${ZFS_CMD} '${import_pool}'"
echo "Message: $ZFS_STDERR" echo "Message: ${ZFS_STDERR}"
echo "Error: $ZFS_ERROR" echo "Error: ${ZFS_ERROR}"
echo "" echo ""
echo "Failed to import pool '$import_pool'." echo "Failed to import pool '${import_pool}'."
echo "Manually import the pool and exit." echo "Manually import the pool and exit."
shell shell
fi fi
fi fi
[ "$quiet" != "y" ] && zfs_log_end_msg [ "${quiet}" != "y" ] && zfs_log_end_msg
POOL_IMPORTED=1 POOL_IMPORTED=1
return 0 return 0
@ -274,14 +274,13 @@ load_module_initrd()
{ {
ZFS_INITRD_PRE_MOUNTROOT_SLEEP=${ROOTDELAY:-0} ZFS_INITRD_PRE_MOUNTROOT_SLEEP=${ROOTDELAY:-0}
if [ "$ZFS_INITRD_PRE_MOUNTROOT_SLEEP" -gt 0 ]; then 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." [ "${quiet}" != "y" ] && zfs_log_begin_msg "Delaying for up to '${ZFS_INITRD_PRE_MOUNTROOT_SLEEP}' seconds."
fi fi
START=$(/bin/date -u +%s) START="$(/bin/date -u +%s)"
END=$((START+ZFS_INITRD_PRE_MOUNTROOT_SLEEP)) END="$((START+ZFS_INITRD_PRE_MOUNTROOT_SLEEP))"
while true; do while true; do
# Wait for all of the /dev/{hd,sd}[a-z] device nodes to appear. # 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 if command -v wait_for_udev > /dev/null 2>&1 ; then
wait_for_udev 10 wait_for_udev 10
@ -303,24 +302,24 @@ load_module_initrd()
ret=1 ret=1
fi fi
[ "$(/bin/date -u +%s)" -gt "$END" ] && break [ "$(/bin/date -u +%s)" -gt "${END}" ] && break
sleep 1 sleep 1
done done
if [ "$ZFS_INITRD_PRE_MOUNTROOT_SLEEP" -gt 0 ]; then if [ "${ZFS_INITRD_PRE_MOUNTROOT_SLEEP}" -gt 0 ]; then
[ "$quiet" != "y" ] && zfs_log_end_msg [ "${quiet}" != "y" ] && zfs_log_end_msg
fi fi
[ "$ret" -ne 0 ] && return 1 [ "${ret}" -ne 0 ] && return 1
if [ "$ZFS_INITRD_POST_MODPROBE_SLEEP" -gt 0 ] 2>/dev/null if [ "${ZFS_INITRD_POST_MODPROBE_SLEEP}" -gt 0 ] 2>/dev/null
then then
if [ "$quiet" != "y" ]; then if [ "${quiet}" != "y" ]; then
zfs_log_begin_msg "Sleeping for" \ zfs_log_begin_msg "Sleeping for" \
"$ZFS_INITRD_POST_MODPROBE_SLEEP seconds..." "${ZFS_INITRD_POST_MODPROBE_SLEEP} seconds..."
fi fi
sleep "$ZFS_INITRD_POST_MODPROBE_SLEEP" sleep "${ZFS_INITRD_POST_MODPROBE_SLEEP}"
[ "$quiet" != "y" ] && zfs_log_end_msg [ "${quiet}" != "y" ] && zfs_log_end_msg
fi fi
return 0 return 0
@ -329,71 +328,71 @@ load_module_initrd()
# Mount a given filesystem # Mount a given filesystem
mount_fs() mount_fs()
{ {
mount_fs="$1" mount_fs="${1}"
# Check that the filesystem exists # Check that the filesystem exists
"${ZFS}" list -oname -tfilesystem -H "${mount_fs}" > /dev/null 2>&1 || return 1 "${ZFS}" list -oname -tfilesystem -H "${mount_fs}" > /dev/null 2>&1 || return 1
# Skip filesystems with canmount=off. The root fs should not have # Skip filesystems with canmount=off. The root fs should not have
# canmount=off, but ignore it for backwards compatibility just in case. # canmount=off, but ignore it for backwards compatibility just in case.
if [ "$mount_fs" != "${ZFS_BOOTFS}" ] if [ "${mount_fs}" != "${ZFS_BOOTFS}" ]
then then
canmount=$(get_fs_value "$mount_fs" canmount) canmount="$(get_fs_value "${mount_fs}" canmount)"
[ "$canmount" = "off" ] && return 0 [ "${canmount}" = "off" ] && return 0
fi fi
# Need the _original_ datasets mountpoint! # Need the _original_ datasets mountpoint!
mountpoint=$(get_fs_value "$mount_fs" mountpoint) mountpoint="$(get_fs_value "${mount_fs}" mountpoint)"
ZFS_CMD="mount.zfs -o zfsutil" ZFS_CMD="mount.zfs -o zfsutil"
if [ "$mountpoint" = "legacy" ] || [ "$mountpoint" = "none" ]; then if [ "${mountpoint}" = "legacy" ] || [ "${mountpoint}" = "none" ]; then
# Can't use the mountpoint property. Might be one of our # Can't use the mountpoint property. Might be one of our
# clones. Check the 'org.zol:mountpoint' property set in # clones. Check the 'org.zol:mountpoint' property set in
# clone_snap() if that's usable. # clone_snap() if that's usable.
mountpoint1=$(get_fs_value "$mount_fs" org.zol:mountpoint) mountpoint1="$(get_fs_value "${mount_fs}" org.zol:mountpoint)"
if [ "$mountpoint1" = "legacy" ] || if [ "${mountpoint1}" = "legacy" ] ||
[ "$mountpoint1" = "none" ] || [ "${mountpoint1}" = "none" ] ||
[ "$mountpoint1" = "-" ] [ "${mountpoint1}" = "-" ]
then then
if [ "$mount_fs" != "${ZFS_BOOTFS}" ]; then if [ "${mount_fs}" != "${ZFS_BOOTFS}" ]; then
# We don't have a proper mountpoint and this # We don't have a proper mountpoint and this
# isn't the root fs. # isn't the root fs.
return 0 return 0
fi fi
if [ "$mountpoint" = "legacy" ]; then if [ "${mountpoint}" = "legacy" ]; then
ZFS_CMD="mount.zfs" ZFS_CMD="mount.zfs"
fi fi
# Last hail-mary: Hope 'rootmnt' is set! # Last hail-mary: Hope 'rootmnt' is set!
mountpoint="" mountpoint=""
else else
mountpoint="$mountpoint1" mountpoint="${mountpoint1}"
fi fi
fi fi
# Possibly decrypt a filesystem using native encryption. # Possibly decrypt a filesystem using native encryption.
decrypt_fs "$mount_fs" decrypt_fs "${mount_fs}"
[ "$quiet" != "y" ] && \ [ "${quiet}" != "y" ] && \
zfs_log_begin_msg "Mounting '${mount_fs}' on '${rootmnt}/${mountpoint}'" zfs_log_begin_msg "Mounting '${mount_fs}' on '${rootmnt}/${mountpoint}'"
[ -n "${ZFS_DEBUG}" ] && \ [ -n "${ZFS_DEBUG}" ] && \
zfs_log_begin_msg "CMD: '$ZFS_CMD ${mount_fs} ${rootmnt}/${mountpoint}'" zfs_log_begin_msg "CMD: '${ZFS_CMD} ${mount_fs} ${rootmnt}/${mountpoint}'"
ZFS_STDERR=$(${ZFS_CMD} "${mount_fs}" "${rootmnt}/${mountpoint}" 2>&1) ZFS_STDERR="$(${ZFS_CMD} "${mount_fs}" "${rootmnt}/${mountpoint}" 2>&1)"
ZFS_ERROR=$? ZFS_ERROR="${?}"
if [ "${ZFS_ERROR}" != 0 ] if [ "${ZFS_ERROR}" != 0 ]
then then
[ "$quiet" != "y" ] && zfs_log_failure_msg "${ZFS_ERROR}" [ "${quiet}" != "y" ] && zfs_log_failure_msg "${ZFS_ERROR}"
disable_plymouth disable_plymouth
echo "" echo ""
echo "Command: ${ZFS_CMD} ${mount_fs} ${rootmnt}/${mountpoint}" echo "Command: ${ZFS_CMD} ${mount_fs} ${rootmnt}/${mountpoint}"
echo "Message: $ZFS_STDERR" echo "Message: ${ZFS_STDERR}"
echo "Error: $ZFS_ERROR" echo "Error: ${ZFS_ERROR}"
echo "" echo ""
echo "Failed to mount ${mount_fs} on ${rootmnt}/${mountpoint}." echo "Failed to mount ${mount_fs} on ${rootmnt}/${mountpoint}."
echo "Manually mount the filesystem and exit." echo "Manually mount the filesystem and exit."
shell shell
else else
[ "$quiet" != "y" ] && zfs_log_end_msg [ "${quiet}" != "y" ] && zfs_log_end_msg
fi fi
return 0 return 0
@ -402,10 +401,10 @@ mount_fs()
# Unlock a ZFS native encrypted filesystem. # Unlock a ZFS native encrypted filesystem.
decrypt_fs() decrypt_fs()
{ {
decrypt_fs="$1" decrypt_fs="${1}"
# If pool encryption is active and the zfs command understands '-o encryption' # If pool encryption is active and the zfs command understands '-o encryption'
if [ "$(zpool list -H -o feature@encryption "${decrypt_fs%%/*}")" = 'active' ]; then if [ "$("${ZPOOL}" list -H -o feature@encryption "${decrypt_fs%%/*}")" = 'active' ]; then
# Determine dataset that holds key for root dataset # Determine dataset that holds key for root dataset
ENCRYPTIONROOT="$(get_fs_value "${decrypt_fs}" encryptionroot)" ENCRYPTIONROOT="$(get_fs_value "${decrypt_fs}" encryptionroot)"
@ -417,28 +416,28 @@ decrypt_fs()
if ! [ "${ENCRYPTIONROOT}" = "-" ]; then if ! [ "${ENCRYPTIONROOT}" = "-" ]; then
KEYSTATUS="$(get_fs_value "${ENCRYPTIONROOT}" keystatus)" KEYSTATUS="$(get_fs_value "${ENCRYPTIONROOT}" keystatus)"
# Continue only if the key needs to be loaded # Continue only if the key needs to be loaded
[ "$KEYSTATUS" = "unavailable" ] || return 0 [ "${KEYSTATUS}" = "unavailable" ] || return 0
# Try extensions first # Try extensions first
for f in "/etc/zfs/initramfs-tools-load-key" "/etc/zfs/initramfs-tools-load-key.d/"*; do for key in "/etc/zfs/initramfs-tools-load-key" "/etc/zfs/initramfs-tools-load-key.d/"*; do
[ -r "$f" ] || continue [ -r "${key}" ] || continue
(. "$f") && { (. "${key}") && {
# Successful return and actually-loaded key: we're done # Successful return and actually-loaded key: we're done
KEYSTATUS="$(get_fs_value "${ENCRYPTIONROOT}" keystatus)" KEYSTATUS="$(get_fs_value "${ENCRYPTIONROOT}" keystatus)"
[ "$KEYSTATUS" = "unavailable" ] || return 0 [ "${KEYSTATUS}" = "unavailable" ] || return 0
} }
done done
# Do not prompt if key is stored noninteractively, # Do not prompt if key is stored noninteractively,
if ! [ "${KEYLOCATION}" = "prompt" ]; then if ! [ "${KEYLOCATION}" = "prompt" ]; then
$ZFS load-key "${ENCRYPTIONROOT}" "${ZFS}" load-key "${ENCRYPTIONROOT}"
# Prompt with plymouth, if active # Prompt with plymouth, if active
elif /bin/plymouth --ping 2>/dev/null; then elif /bin/plymouth --ping 2>/dev/null; then
echo "plymouth" > /run/zfs_console_askpwd_cmd echo "plymouth" > /run/zfs_console_askpwd_cmd
for _ in 1 2 3; do for _ in 1 2 3; do
plymouth ask-for-password --prompt "Encrypted ZFS password for ${ENCRYPTIONROOT}" | \ plymouth ask-for-password --prompt "Encrypted ZFS password for ${ENCRYPTIONROOT}" | \
$ZFS load-key "${ENCRYPTIONROOT}" && break "${ZFS}" load-key "${ENCRYPTIONROOT}" && break
done done
# Prompt with systemd, if active # Prompt with systemd, if active
@ -446,7 +445,7 @@ decrypt_fs()
echo "systemd-ask-password" > /run/zfs_console_askpwd_cmd echo "systemd-ask-password" > /run/zfs_console_askpwd_cmd
for _ in 1 2 3; do for _ in 1 2 3; do
systemd-ask-password --no-tty "Encrypted ZFS password for ${ENCRYPTIONROOT}" | \ systemd-ask-password --no-tty "Encrypted ZFS password for ${ENCRYPTIONROOT}" | \
$ZFS load-key "${ENCRYPTIONROOT}" && break "${ZFS}" load-key "${ENCRYPTIONROOT}" && break
done done
# Prompt with ZFS tty, otherwise # Prompt with ZFS tty, otherwise
@ -455,8 +454,8 @@ decrypt_fs()
echo "load-key" > /run/zfs_console_askpwd_cmd echo "load-key" > /run/zfs_console_askpwd_cmd
read -r storeprintk _ < /proc/sys/kernel/printk read -r storeprintk _ < /proc/sys/kernel/printk
echo 7 > /proc/sys/kernel/printk echo 7 > /proc/sys/kernel/printk
$ZFS load-key "${ENCRYPTIONROOT}" "${ZFS}" load-key "${ENCRYPTIONROOT}"
echo "$storeprintk" > /proc/sys/kernel/printk echo "${storeprintk}" > /proc/sys/kernel/printk
fi fi
fi fi
fi fi
@ -467,30 +466,30 @@ decrypt_fs()
# Destroy a given filesystem. # Destroy a given filesystem.
destroy_fs() destroy_fs()
{ {
destroy_fs="$1" destroy_fs="${1}"
[ "$quiet" != "y" ] && \ [ "${quiet}" != "y" ] && \
zfs_log_begin_msg "Destroying '$destroy_fs'" zfs_log_begin_msg "Destroying '${destroy_fs}'"
ZFS_CMD="${ZFS} destroy $destroy_fs" ZFS_CMD="${ZFS} destroy ${destroy_fs}"
ZFS_STDERR="$(${ZFS_CMD} 2>&1)" ZFS_STDERR="$(${ZFS_CMD} 2>&1)"
ZFS_ERROR="$?" ZFS_ERROR="${?}"
if [ "${ZFS_ERROR}" != 0 ] if [ "${ZFS_ERROR}" != 0 ]
then then
[ "$quiet" != "y" ] && zfs_log_failure_msg "${ZFS_ERROR}" [ "${quiet}" != "y" ] && zfs_log_failure_msg "${ZFS_ERROR}"
disable_plymouth disable_plymouth
echo "" echo ""
echo "Command: $ZFS_CMD" echo "Command: ${ZFS_CMD}"
echo "Message: $ZFS_STDERR" echo "Message: ${ZFS_STDERR}"
echo "Error: $ZFS_ERROR" echo "Error: ${ZFS_ERROR}"
echo "" echo ""
echo "Failed to destroy '$destroy_fs'. Please make sure that '$destroy_fs' is not available." echo "Failed to destroy '${destroy_fs}'. Please make sure that it is not available."
echo "Hint: Try: zfs destroy -Rfn $destroy_fs" echo "Hint: Try: zfs destroy -Rfn ${destroy_fs}"
echo "If this dryrun looks good, then remove the 'n' from '-Rfn' and try again." echo "If this dryrun looks good, then remove the 'n' from '-Rfn' and try again."
shell shell
else else
[ "$quiet" != "y" ] && zfs_log_end_msg [ "${quiet}" != "y" ] && zfs_log_end_msg
fi fi
return 0 return 0
@ -502,11 +501,11 @@ destroy_fs()
# mounted with a 'zfs mount -a' in the init/systemd scripts). # mounted with a 'zfs mount -a' in the init/systemd scripts).
clone_snap() clone_snap()
{ {
clone_snap="$1" clone_snap="${1}"
clone_destfs="$2" clone_destfs="${2}"
clone_mountpoint="$3" clone_mountpoint="${3}"
[ "$quiet" != "y" ] && zfs_log_begin_msg "Cloning '$clone_snap' to '$clone_destfs'" [ "${quiet}" != "y" ] && zfs_log_begin_msg "Cloning '${clone_snap}' to '${clone_destfs}'"
# Clone the snapshot into a dataset we can boot from # Clone the snapshot into a dataset we can boot from
# + We don't want this filesystem to be automatically mounted, we # + We don't want this filesystem to be automatically mounted, we
@ -515,25 +514,25 @@ clone_snap()
# We use the 'org.zol:mountpoint' property to remember the mountpoint. # We use the 'org.zol:mountpoint' property to remember the mountpoint.
ZFS_CMD="${ZFS} clone -o canmount=noauto -o mountpoint=none" ZFS_CMD="${ZFS} clone -o canmount=noauto -o mountpoint=none"
ZFS_CMD="${ZFS_CMD} -o org.zol:mountpoint=${clone_mountpoint}" ZFS_CMD="${ZFS_CMD} -o org.zol:mountpoint=${clone_mountpoint}"
ZFS_CMD="${ZFS_CMD} $clone_snap $clone_destfs" ZFS_CMD="${ZFS_CMD} ${clone_snap} ${clone_destfs}"
ZFS_STDERR="$(${ZFS_CMD} 2>&1)" ZFS_STDERR="$(${ZFS_CMD} 2>&1)"
ZFS_ERROR="$?" ZFS_ERROR="${?}"
if [ "${ZFS_ERROR}" != 0 ] if [ "${ZFS_ERROR}" != 0 ]
then then
[ "$quiet" != "y" ] && zfs_log_failure_msg "${ZFS_ERROR}" [ "${quiet}" != "y" ] && zfs_log_failure_msg "${ZFS_ERROR}"
disable_plymouth disable_plymouth
echo "" echo ""
echo "Command: $ZFS_CMD" echo "Command: ${ZFS_CMD}"
echo "Message: $ZFS_STDERR" echo "Message: ${ZFS_STDERR}"
echo "Error: $ZFS_ERROR" echo "Error: ${ZFS_ERROR}"
echo "" echo ""
echo "Failed to clone snapshot." echo "Failed to clone snapshot."
echo "Make sure that any problems are corrected and then make sure" echo "Make sure that any problems are corrected and then make sure"
echo "that the dataset '$clone_destfs' exists and is bootable." echo "that the dataset '${clone_destfs}' exists and is bootable."
shell shell
else else
[ "$quiet" != "y" ] && zfs_log_end_msg [ "${quiet}" != "y" ] && zfs_log_end_msg
fi fi
return 0 return 0
@ -542,27 +541,27 @@ clone_snap()
# Rollback a given snapshot. # Rollback a given snapshot.
rollback_snap() rollback_snap()
{ {
rollback_snap="$1" rollback_snap="${1}"
[ "$quiet" != "y" ] && zfs_log_begin_msg "Rollback $rollback_snap" [ "${quiet}" != "y" ] && zfs_log_begin_msg "Rollback ${rollback_snap}"
ZFS_CMD="${ZFS} rollback -Rf $rollback_snap" ZFS_CMD="${ZFS} rollback -Rf ${rollback_snap}"
ZFS_STDERR="$(${ZFS_CMD} 2>&1)" ZFS_STDERR="$(${ZFS_CMD} 2>&1)"
ZFS_ERROR="$?" ZFS_ERROR="${?}"
if [ "${ZFS_ERROR}" != 0 ] if [ "${ZFS_ERROR}" != 0 ]
then then
[ "$quiet" != "y" ] && zfs_log_failure_msg "${ZFS_ERROR}" [ "${quiet}" != "y" ] && zfs_log_failure_msg "${ZFS_ERROR}"
disable_plymouth disable_plymouth
echo "" echo ""
echo "Command: $ZFS_CMD" echo "Command: ${ZFS_CMD}"
echo "Message: $ZFS_STDERR" echo "Message: ${ZFS_STDERR}"
echo "Error: $ZFS_ERROR" echo "Error: ${ZFS_ERROR}"
echo "" echo ""
echo "Failed to rollback snapshot." echo "Failed to rollback snapshot."
shell shell
else else
[ "$quiet" != "y" ] && zfs_log_end_msg [ "${quiet}" != "y" ] && zfs_log_end_msg
fi fi
return 0 return 0
@ -572,7 +571,7 @@ rollback_snap()
# to the user to choose from. # to the user to choose from.
ask_user_snap() ask_user_snap()
{ {
ask_snap="$1" ask_snap="${1}"
# We need to temporarily disable debugging. Set 'debug' so we # We need to temporarily disable debugging. Set 'debug' so we
# remember to enabled it again. # remember to enabled it again.
@ -590,18 +589,18 @@ ask_user_snap()
" set -- $("${ZFS}" list -H -oname -tsnapshot -r "${ask_snap}") " set -- $("${ZFS}" list -H -oname -tsnapshot -r "${ask_snap}")
i=1 i=1
for snap in "$@"; do for snap in "${@}"; do
echo " $i: $snap" echo " ${i}: ${snap}"
i=$((i + 1)) i="$((i + 1))"
done > /dev/stderr done > /dev/stderr
# expr instead of test here because [ a -lt 0 ] errors out, # expr instead of test here because [ a -lt 0 ] errors out,
# but expr falls back to lexicographical, which works out right # but expr falls back to lexicographical, which works out right
snapnr=0 snapnr=0
while expr "$snapnr" "<" 1 > /dev/null || while expr "${snapnr}" "<" 1 > /dev/null ||
expr "$snapnr" ">" "$#" > /dev/null expr "${snapnr}" ">" "${#}" > /dev/null
do do
printf "%s" "Snap nr [1-$#]? " > /dev/stderr printf "%s" "Snap nr [1-${#}]? " > /dev/stderr
read -r snapnr read -r snapnr
done done
@ -611,12 +610,12 @@ ask_user_snap()
set -x set -x
fi fi
eval echo '$'"$snapnr" eval echo '$'"${snapnr}"
} }
setup_snapshot_booting() setup_snapshot_booting()
{ {
boot_snap="$1" boot_snap="${1}"
retval=0 retval=0
# Make sure that the snapshot specified actually exists. # Make sure that the snapshot specified actually exists.
@ -627,7 +626,7 @@ setup_snapshot_booting()
snap="$(ask_user_snap "${boot_snap%%@*}")" snap="$(ask_user_snap "${boot_snap%%@*}")"
fi fi
# Separate the full snapshot ('$snap') into it's filesystem and # Separate the full snapshot ('${snap}') into it's filesystem and
# snapshot names. Would have been nice with a split() function.. # snapshot names. Would have been nice with a split() function..
rootfs="${boot_snap%%@*}" rootfs="${boot_snap%%@*}"
snapname="${boot_snap##*@}" snapname="${boot_snap##*@}"
@ -639,9 +638,9 @@ setup_snapshot_booting()
# already exists, destroy it. Recursively # already exists, destroy it. Recursively
if [ -n "$(get_fs_value "${rootfs}_${snapname}" type)" ] if [ -n "$(get_fs_value "${rootfs}_${snapname}" type)" ]
then then
filesystems=$("${ZFS}" list -oname -tfilesystem -H \ filesystems="$("${ZFS}" list -oname -tfilesystem -H \
-r -Sname "${ZFS_BOOTFS}") -r -Sname "${ZFS_BOOTFS}")"
for fs in $filesystems; do for fs in ${filesystems}; do
destroy_fs "${boot_snap}" destroy_fs "${boot_snap}"
done done
fi fi
@ -655,7 +654,7 @@ setup_snapshot_booting()
if grep -qiE '(^|[^\\](\\\\)* )(rollback)=(on|yes|1)( |$)' /proc/cmdline if grep -qiE '(^|[^\\](\\\\)* )(rollback)=(on|yes|1)( |$)' /proc/cmdline
then then
# Rollback snapshot # Rollback snapshot
rollback_snap "$s" || retval=$((retval + 1)) rollback_snap "${s}" || retval="$((retval + 1))"
ZFS_BOOTFS="${rootfs}" ZFS_BOOTFS="${rootfs}"
else else
# Setup a destination filesystem name. # Setup a destination filesystem name.
@ -664,18 +663,18 @@ setup_snapshot_booting()
# rpool/ROOT/debian/boot@snap2 => rpool/ROOT/debian_snap2/boot # rpool/ROOT/debian/boot@snap2 => rpool/ROOT/debian_snap2/boot
# rpool/ROOT/debian/usr@snap2 => rpool/ROOT/debian_snap2/usr # rpool/ROOT/debian/usr@snap2 => rpool/ROOT/debian_snap2/usr
# rpool/ROOT/debian/var@snap2 => rpool/ROOT/debian_snap2/var # rpool/ROOT/debian/var@snap2 => rpool/ROOT/debian_snap2/var
subfs="${s##"$rootfs"}" subfs="${s##"${rootfs}"}"
subfs="${subfs%%@"$snapname"}" subfs="${subfs%%@"${snapname}"}"
destfs="${rootfs}_${snapname}" # base fs. destfs="${rootfs}_${snapname}" # base fs.
[ -n "$subfs" ] && destfs="${destfs}$subfs" # + sub fs. [ -n "${subfs}" ] && destfs="${destfs}${subfs}" # + sub fs.
# Get the mountpoint of the filesystem, to be used # Get the mountpoint of the filesystem, to be used
# with clone_snap(). If legacy or none, then use # with clone_snap(). If legacy or none, then use
# the sub fs value. # the sub fs value.
mountpoint=$(get_fs_value "${s%%@*}" mountpoint) mountpoint="$(get_fs_value "${s%%@*}" mountpoint)"
if [ "$mountpoint" = "legacy" ] || \ if [ "${mountpoint}" = "legacy" ] || \
[ "$mountpoint" = "none" ] [ "${mountpoint}" = "none" ]
then then
if [ -n "${subfs}" ]; then if [ -n "${subfs}" ]; then
mountpoint="${subfs}" mountpoint="${subfs}"
@ -686,8 +685,8 @@ setup_snapshot_booting()
# Clone the snapshot into its own # Clone the snapshot into its own
# filesystem # filesystem
clone_snap "$s" "${destfs}" "${mountpoint}" || \ clone_snap "${s}" "${destfs}" "${mountpoint}" || \
retval=$((retval + 1)) retval="$((retval + 1))"
fi fi
done done
@ -740,11 +739,11 @@ mountroot()
# Compatibility: 'ROOT' is for Debian GNU/Linux (etc), # Compatibility: 'ROOT' is for Debian GNU/Linux (etc),
# 'root' is for Redhat/Fedora (etc), # 'root' is for Redhat/Fedora (etc),
# 'REAL_ROOT' is for Gentoo # 'REAL_ROOT' is for Gentoo
if [ -z "$ROOT" ] if [ -z "${ROOT}" ]
then then
[ -n "$root" ] && ROOT=${root} [ -n "${root}" ] && ROOT="${root}"
[ -n "$REAL_ROOT" ] && ROOT=${REAL_ROOT} [ -n "${REAL_ROOT}" ] && ROOT="${REAL_ROOT}"
fi fi
# ------------ # ------------
@ -752,18 +751,18 @@ mountroot()
# Compatibility: 'rootmnt' is for Debian GNU/Linux (etc), # Compatibility: 'rootmnt' is for Debian GNU/Linux (etc),
# 'NEWROOT' is for RedHat/Fedora (etc), # 'NEWROOT' is for RedHat/Fedora (etc),
# 'NEW_ROOT' is for Gentoo # 'NEW_ROOT' is for Gentoo
if [ -z "$rootmnt" ] if [ -z "${rootmnt}" ]
then then
[ -n "$NEWROOT" ] && rootmnt=${NEWROOT} [ -n "${NEWROOT}" ] && rootmnt="${NEWROOT}"
[ -n "$NEW_ROOT" ] && rootmnt=${NEW_ROOT} [ -n "${NEW_ROOT}" ] && rootmnt="${NEW_ROOT}"
fi fi
# ------------ # ------------
# No longer set in the defaults file, but it could have been set in # No longer set in the defaults file, but it could have been set in
# get_pools() in some circumstances. If it's something, but not 'yes', # get_pools() in some circumstances. If it's something, but not 'yes',
# it's no good to us. # it's no good to us.
[ -n "$USE_DISK_BY_ID" ] && [ "$USE_DISK_BY_ID" != 'yes' ] && \ [ -n "${USE_DISK_BY_ID}" ] && [ "${USE_DISK_BY_ID}" != 'yes' ] && \
unset USE_DISK_BY_ID unset USE_DISK_BY_ID
# ---------------------------------------------------------------- # ----------------------------------------------------------------
@ -803,19 +802,19 @@ mountroot()
# ------------ # ------------
# Look for 'rpool' and 'bootfs' parameter # Look for 'rpool' and 'bootfs' parameter
[ -n "$rpool" ] && ZFS_RPOOL="${rpool#rpool=}" [ -n "${rpool}" ] && ZFS_RPOOL="${rpool#rpool=}"
[ -n "$bootfs" ] && ZFS_BOOTFS="${bootfs#bootfs=}" [ -n "${bootfs}" ] && ZFS_BOOTFS="${bootfs#bootfs=}"
# ------------ # ------------
# If we have 'ROOT' (see above), but not 'ZFS_BOOTFS', then use # If we have 'ROOT' (see above), but not 'ZFS_BOOTFS', then use
# 'ROOT' # 'ROOT'
[ -n "$ROOT" ] && [ -z "${ZFS_BOOTFS}" ] && ZFS_BOOTFS="$ROOT" [ -n "${ROOT}" ] && [ -z "${ZFS_BOOTFS}" ] && ZFS_BOOTFS="${ROOT}"
# ------------ # ------------
# Check for the `-B zfs-bootfs=%s/%u,...` kind of parameter. # Check for the `-B zfs-bootfs=%s/%u,...` kind of parameter.
# NOTE: Only use the pool name and dataset. The rest is not # NOTE: Only use the pool name and dataset. The rest is not
# supported by OpenZFS (whatever it's for). # supported by OpenZFS (whatever it's for).
if [ -z "$ZFS_RPOOL" ] if [ -z "${ZFS_RPOOL}" ]
then then
# The ${zfs-bootfs} variable is set at the kernel command # The ${zfs-bootfs} variable is set at the kernel command
# line, usually by GRUB, but it cannot be referenced here # line, usually by GRUB, but it cannot be referenced here
@ -826,12 +825,12 @@ mountroot()
# stripping the zfs-bootfs= prefix. Let the shell handle # stripping the zfs-bootfs= prefix. Let the shell handle
# quoting through the eval command: # quoting through the eval command:
# shellcheck disable=SC2046 # shellcheck disable=SC2046
eval ZFS_RPOOL=$(set | sed -n -e 's,^zfs-bootfs=,,p') eval ZFS_RPOOL="$(set | sed -n -e 's,^zfs-bootfs=,,p')"
fi fi
# ------------ # ------------
# No root fs or pool specified - do auto detect. # No root fs or pool specified - do auto detect.
if [ -z "$ZFS_RPOOL" ] && [ -z "${ZFS_BOOTFS}" ] if [ -z "${ZFS_RPOOL}" ] && [ -z "${ZFS_BOOTFS}" ]
then then
# Do auto detect. Do this by 'cheating' - set 'root=zfs:AUTO' # Do auto detect. Do this by 'cheating' - set 'root=zfs:AUTO'
# which will be caught later # which will be caught later
@ -842,7 +841,7 @@ mountroot()
# F I N D A N D I M P O R T C O R R E C T P O O L # F I N D A N D I M P O R T C O R R E C T P O O L
# ------------ # ------------
if [ "$ROOT" = "zfs:AUTO" ] if [ "${ROOT}" = "zfs:AUTO" ]
then then
# Try to detect both pool and root fs. # Try to detect both pool and root fs.
@ -851,29 +850,29 @@ mountroot()
# this says "zfs:AUTO" here and interferes with checks later # this says "zfs:AUTO" here and interferes with checks later
ZFS_BOOTFS= ZFS_BOOTFS=
[ "$quiet" != "y" ] && \ [ "${quiet}" != "y" ] && \
zfs_log_begin_msg "Attempting to import additional pools." zfs_log_begin_msg "Attempting to import additional pools."
# Get a list of pools available for import # Get a list of pools available for import
if [ -n "$ZFS_RPOOL" ] if [ -n "${ZFS_RPOOL}" ]
then then
# We've specified a pool - check only that # We've specified a pool - check only that
POOLS=$ZFS_RPOOL POOLS="${ZFS_RPOOL}"
else else
POOLS=$(get_pools) POOLS="$(get_pools)"
fi fi
OLD_IFS="$IFS" ; IFS=";" OLD_IFS="${IFS}" ; IFS=";"
for pool in $POOLS for pool in ${POOLS}
do do
[ -z "$pool" ] && continue [ -z "${pool}" ] && continue
IFS="$OLD_IFS" import_pool "$pool" IFS="${OLD_IFS}" import_pool "${pool}"
IFS="$OLD_IFS" find_rootfs "$pool" && break IFS="${OLD_IFS}" find_rootfs "${pool}" && break
done done
IFS="$OLD_IFS" IFS="${OLD_IFS}"
[ "$quiet" != "y" ] && zfs_log_end_msg "$ZFS_ERROR" [ "${quiet}" != "y" ] && zfs_log_end_msg "${ZFS_ERROR}"
else else
# No auto - use value from the command line option. # No auto - use value from the command line option.
@ -885,15 +884,15 @@ mountroot()
fi fi
# Import the pool (if not already done so in the AUTO check above). # Import the pool (if not already done so in the AUTO check above).
if [ -n "$ZFS_RPOOL" ] && [ -z "${POOL_IMPORTED}" ] if [ -n "${ZFS_RPOOL}" ] && [ -z "${POOL_IMPORTED}" ]
then then
[ "$quiet" != "y" ] && \ [ "${quiet}" != "y" ] && \
zfs_log_begin_msg "Importing ZFS root pool '$ZFS_RPOOL'" zfs_log_begin_msg "Importing ZFS root pool '${ZFS_RPOOL}'"
import_pool "${ZFS_RPOOL}" import_pool "${ZFS_RPOOL}"
find_rootfs "${ZFS_RPOOL}" find_rootfs "${ZFS_RPOOL}"
[ "$quiet" != "y" ] && zfs_log_end_msg [ "${quiet}" != "y" ] && zfs_log_end_msg
fi fi
if [ -z "${POOL_IMPORTED}" ] if [ -z "${POOL_IMPORTED}" ]
@ -901,9 +900,9 @@ mountroot()
# No pool imported, this is serious! # No pool imported, this is serious!
disable_plymouth disable_plymouth
echo "" echo ""
echo "Command: $ZFS_CMD" echo "Command: ${ZFS_CMD}"
echo "Message: $ZFS_STDERR" echo "Message: ${ZFS_STDERR}"
echo "Error: $ZFS_ERROR" echo "Error: ${ZFS_ERROR}"
echo "" echo ""
echo "No pool imported. Manually import the root pool" echo "No pool imported. Manually import the root pool"
echo "at the command prompt and then exit." echo "at the command prompt and then exit."
@ -914,10 +913,10 @@ mountroot()
# In case the pool was specified as guid, resolve guid to name # In case the pool was specified as guid, resolve guid to name
pool="$("${ZPOOL}" get -H -o name,value name,guid | \ pool="$("${ZPOOL}" get -H -o name,value name,guid | \
awk -v pool="${ZFS_RPOOL}" '$2 == pool { print $1 }')" awk -v pool="${ZFS_RPOOL}" '$2 == pool { print $1 }')"
if [ -n "$pool" ]; then if [ -n "${pool}" ]; then
# If $ZFS_BOOTFS contains guid, replace the guid portion with $pool # If ${ZFS_BOOTFS} contains guid, replace the guid portion with ${pool}.
ZFS_BOOTFS=$(echo "$ZFS_BOOTFS" | \ ZFS_BOOTFS="$(echo "${ZFS_BOOTFS}" | \
sed -e "s/$("${ZPOOL}" get -H -o value guid "$pool")/$pool/g") sed -e "s/$("${ZPOOL}" get -H -o value guid "${pool}")/${pool}/g")"
ZFS_RPOOL="${pool}" ZFS_RPOOL="${pool}"
fi fi
@ -942,8 +941,8 @@ mountroot()
echo "Error: Unknown root filesystem - no 'bootfs' pool property and" echo "Error: Unknown root filesystem - no 'bootfs' pool property and"
echo " not specified on the kernel command line." echo " not specified on the kernel command line."
echo "" echo ""
echo "Manually mount the root filesystem on $rootmnt and then exit." echo "Manually mount the root filesystem on ${rootmnt} and then exit."
echo "Hint: Try: mount -o zfsutil -t zfs ${ZFS_RPOOL-rpool}/ROOT/system $rootmnt" echo "Hint: Try: mount -o zfsutil -t zfs ${ZFS_RPOOL:-rpool}/ROOT/system ${rootmnt}"
shell shell
fi fi
@ -952,7 +951,7 @@ mountroot()
# * Ideally, the root filesystem would be mounted like this: # * Ideally, the root filesystem would be mounted like this:
# #
# zpool import -R "$rootmnt" -N "$ZFS_RPOOL" # zpool import -R "${rootmnt}" -N "${ZFS_RPOOL}"
# zfs mount -o mountpoint=/ "${ZFS_BOOTFS}" # zfs mount -o mountpoint=/ "${ZFS_BOOTFS}"
# #
# but the MOUNTPOINT prefix is preserved on descendent filesystem # but the MOUNTPOINT prefix is preserved on descendent filesystem
@ -967,14 +966,14 @@ mountroot()
# Go through the complete list (recursively) of all filesystems below # Go through the complete list (recursively) of all filesystems below
# the real root dataset # the real root dataset
filesystems="$("${ZFS}" list -oname -tfilesystem -H -r "${ZFS_BOOTFS}")" filesystems="$("${ZFS}" list -oname -tfilesystem -H -r "${ZFS_BOOTFS}")"
OLD_IFS="$IFS" ; IFS=" OLD_IFS="${IFS}" ; IFS="
" "
for fs in $filesystems; do for fs in ${filesystems}; do
IFS="$OLD_IFS" mount_fs "$fs" IFS="${OLD_IFS}" mount_fs "${fs}"
done done
IFS="$OLD_IFS" IFS="${OLD_IFS}"
for fs in $ZFS_INITRD_ADDITIONAL_DATASETS; do for fs in ${ZFS_INITRD_ADDITIONAL_DATASETS}; do
mount_fs "$fs" mount_fs "${fs}"
done done
touch /run/zfs_unlock_complete touch /run/zfs_unlock_complete
@ -1001,8 +1000,8 @@ mountroot()
printf "%s" " 'c' for shell, 'r' for reboot, 'ENTER' to continue. " printf "%s" " 'c' for shell, 'r' for reboot, 'ENTER' to continue. "
read -r b read -r b
[ "$b" = "c" ] && /bin/sh [ "${b}" = "c" ] && /bin/sh
[ "$b" = "r" ] && reboot -f [ "${b}" = "r" ] && reboot -f
set +x set +x
fi fi
@ -1013,10 +1012,10 @@ mountroot()
then then
if [ -f "/scripts/local-bottom" ] || [ -d "/scripts/local-bottom" ] if [ -f "/scripts/local-bottom" ] || [ -d "/scripts/local-bottom" ]
then then
[ "$quiet" != "y" ] && \ [ "${quiet}" != "y" ] && \
zfs_log_begin_msg "Running /scripts/local-bottom" zfs_log_begin_msg "Running /scripts/local-bottom"
run_scripts /scripts/local-bottom run_scripts /scripts/local-bottom
[ "$quiet" != "y" ] && zfs_log_end_msg [ "${quiet}" != "y" ] && zfs_log_end_msg
fi fi
fi fi
} }