|
|
|
@@ -5,6 +5,8 @@
|
|
|
|
|
#
|
|
|
|
|
# Enable this by passing boot=zfs on the kernel command line.
|
|
|
|
|
#
|
|
|
|
|
# $quiet, $root, $rpool, $bootfs come from the cmdline:
|
|
|
|
|
# shellcheck disable=SC2154
|
|
|
|
|
|
|
|
|
|
# Source the common functions
|
|
|
|
|
. /etc/zfs/zfs-functions
|
|
|
|
@@ -102,14 +104,10 @@ find_rootfs()
|
|
|
|
|
# Support function to get a list of all pools, separated with ';'
|
|
|
|
|
find_pools()
|
|
|
|
|
{
|
|
|
|
|
CMD="$*"
|
|
|
|
|
|
|
|
|
|
pools=$($CMD 2> /dev/null | \
|
|
|
|
|
pools=$("$@" 2> /dev/null | \
|
|
|
|
|
grep -E "pool:|^[a-zA-Z0-9]" | \
|
|
|
|
|
sed 's@.*: @@' | \
|
|
|
|
|
while read -r pool; do \
|
|
|
|
|
printf "%s" "$pool;"
|
|
|
|
|
done)
|
|
|
|
|
tr '\n' ';')
|
|
|
|
|
|
|
|
|
|
echo "${pools%%;}" # Return without the last ';'.
|
|
|
|
|
}
|
|
|
|
@@ -203,7 +201,7 @@ import_pool()
|
|
|
|
|
# exists).
|
|
|
|
|
if [ -n "$USE_DISK_BY_ID" ] && [ -z "$ZPOOL_IMPORT_PATH" ]
|
|
|
|
|
then
|
|
|
|
|
dirs="$(for dir in $(echo /dev/disk/by-*)
|
|
|
|
|
dirs="$(for dir in /dev/disk/by-*
|
|
|
|
|
do
|
|
|
|
|
# Ignore by-vdev here - we want it first!
|
|
|
|
|
echo "$dir" | grep -q /by-vdev && continue
|
|
|
|
@@ -329,6 +327,7 @@ mount_fs()
|
|
|
|
|
|
|
|
|
|
# Need the _original_ datasets mountpoint!
|
|
|
|
|
mountpoint=$(get_fs_value "$fs" mountpoint)
|
|
|
|
|
ZFS_CMD="mount -o zfsutil -t zfs"
|
|
|
|
|
if [ "$mountpoint" = "legacy" ] || [ "$mountpoint" = "none" ]; then
|
|
|
|
|
# Can't use the mountpoint property. Might be one of our
|
|
|
|
|
# clones. Check the 'org.zol:mountpoint' property set in
|
|
|
|
@@ -348,15 +347,11 @@ mount_fs()
|
|
|
|
|
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"
|
|
|
|
|
else
|
|
|
|
|
# If it's not a legacy filesystem, it can only be a
|
|
|
|
|
# native one...
|
|
|
|
|
ZFS_CMD="mount -o zfsutil -t zfs"
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
ZFS_CMD="mount -o zfsutil -t zfs"
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Possibly decrypt a filesystem using native encryption.
|
|
|
|
@@ -553,7 +548,6 @@ rollback_snap()
|
|
|
|
|
ask_user_snap()
|
|
|
|
|
{
|
|
|
|
|
fs="$1"
|
|
|
|
|
i=1
|
|
|
|
|
|
|
|
|
|
# We need to temporarily disable debugging. Set 'debug' so we
|
|
|
|
|
# remember to enabled it again.
|
|
|
|
@@ -566,16 +560,25 @@ ask_user_snap()
|
|
|
|
|
# Because we need the resulting snapshot, which is sent on
|
|
|
|
|
# stdout to the caller, we use stderr for our questions.
|
|
|
|
|
echo "What snapshot do you want to boot from?" > /dev/stderr
|
|
|
|
|
while read -r snap; do
|
|
|
|
|
echo " $i: ${snap}" > /dev/stderr
|
|
|
|
|
eval "$(echo SNAP_$i=$snap)"
|
|
|
|
|
i=$((i + 1))
|
|
|
|
|
done <<EOT
|
|
|
|
|
$("${ZFS}" list -H -oname -tsnapshot -r "${fs}")
|
|
|
|
|
EOT
|
|
|
|
|
# shellcheck disable=SC2046
|
|
|
|
|
IFS="
|
|
|
|
|
" set -- $("${ZFS}" list -H -oname -tsnapshot -r "${fs}")
|
|
|
|
|
|
|
|
|
|
echo "%s" " Snap nr [1-$((i-1))]? " > /dev/stderr
|
|
|
|
|
read -r snapnr
|
|
|
|
|
i=1
|
|
|
|
|
for snap in "$@"; do
|
|
|
|
|
echo " $i: $snap"
|
|
|
|
|
i=$((i + 1))
|
|
|
|
|
done > /dev/stderr
|
|
|
|
|
|
|
|
|
|
# expr instead of test here because [ a -lt 0 ] errors out,
|
|
|
|
|
# but expr falls back to lexicographical, which works out right
|
|
|
|
|
snapnr=0
|
|
|
|
|
while expr "$snapnr" "<" 1 > /dev/null ||
|
|
|
|
|
expr "$snapnr" ">" "$#" > /dev/null
|
|
|
|
|
do
|
|
|
|
|
printf "%s" "Snap nr [1-$#]? " > /dev/stderr
|
|
|
|
|
read -r snapnr
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Re-enable debugging.
|
|
|
|
|
if [ -n "${debug}" ]; then
|
|
|
|
@@ -583,7 +586,7 @@ EOT
|
|
|
|
|
set -x
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
echo "$(eval echo '$SNAP_'$snapnr)"
|
|
|
|
|
eval echo '$'"$snapnr"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setup_snapshot_booting()
|
|
|
|
@@ -703,7 +706,7 @@ mountroot()
|
|
|
|
|
|
|
|
|
|
# ------------
|
|
|
|
|
# Look for the cache file (if any).
|
|
|
|
|
[ ! -f ${ZPOOL_CACHE} ] && unset ZPOOL_CACHE
|
|
|
|
|
[ ! -f "${ZPOOL_CACHE}" ] && unset ZPOOL_CACHE
|
|
|
|
|
|
|
|
|
|
# ------------
|
|
|
|
|
# Compatibility: 'ROOT' is for Debian GNU/Linux (etc),
|
|
|
|
@@ -793,7 +796,8 @@ mountroot()
|
|
|
|
|
#
|
|
|
|
|
# Reassign the variable by dumping the environment and
|
|
|
|
|
# stripping the zfs-bootfs= prefix. Let the shell handle
|
|
|
|
|
# quoting through the eval command.
|
|
|
|
|
# quoting through the eval command:
|
|
|
|
|
# shellcheck disable=SC2046
|
|
|
|
|
eval ZFS_RPOOL=$(set | sed -n -e 's,^zfs-bootfs=,,p')
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
@@ -947,7 +951,7 @@ mountroot()
|
|
|
|
|
|
|
|
|
|
touch /run/zfs_unlock_complete
|
|
|
|
|
if [ -e /run/zfs_unlock_complete_notify ]; then
|
|
|
|
|
read -r zfs_unlock_complete_notify < /run/zfs_unlock_complete_notify
|
|
|
|
|
read -r < /run/zfs_unlock_complete_notify
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# ------------
|
|
|
|
|