Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions zfsbootmenu/bin/zfs-chroot
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,7 @@
# vim: softtabstop=2 shiftwidth=2 expandtab

cleanup() {
local mounts mp skip mp_re depth filesystem

if [ -n "${mountpoint}" ]; then
if ! umount -R "${mountpoint}" >/dev/null 2>&1 ; then
# thanks, busybox
mounts=()
mp_re="^${mountpoint}"

# shellcheck disable=SC2034
while read -r skip mp skip skip ; do
if [[ "${mp}" =~ ${mp_re} ]]; then
depth="${mp//[!\/]/}"
mounts+=( "${#depth},${mp}" )
fi
done < /proc/self/mounts

while IFS=$'\n' read -r filesystem; do
umount "${filesystem#*,}" || zerror "unable to unmount ${filesystem#*,}"
done <<<"$( printf '%s\n' "${mounts[@]}" | sort -n -k1 -r )"
fi
fi

[ -n "${mountpoint}" ] && recursive_umount "${mountpoint}"
mount_efivarfs

trap - HUP INT QUIT ABRT EXIT
Expand Down
39 changes: 38 additions & 1 deletion zfsbootmenu/lib/zfsbootmenu-core.sh
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ kexec_kernel() {
then
zerror "unable to load ${mnt}${kernel} and ${mnt}${initramfs} into memory"
zerror "${output}"
umount "${mnt}"
recursive_umount "${mnt}"
timed_prompt -d 10 \
-m "$( colorize red 'Unable to load kernel or initramfs into memory' )" \
-m "$( colorize orange "${mnt}${kernel}" )" \
Expand Down Expand Up @@ -2272,3 +2272,40 @@ is_zfs_filesystem() {

return 1
}

# arg1: mount point
# returns: 0 if everything was unmounted, 1 if not

recursive_umount() {
local mounts mountpoint mp skip mp_re depth filesystem ret

mountpoint="${1}"
if [ -z "${mountpoint}" ]; then
zerror "mountpoint undefined"
return 1
fi

ret=0
if ! umount -R "${mountpoint}" >/dev/null 2>&1 ; then
mounts=()
mp_re="^${mountpoint}"

# shellcheck disable=SC2034
while read -r skip mp skip skip ; do
if [[ "${mp}" =~ ${mp_re} ]]; then
depth="${mp//[!\/]/}"
mounts+=( "${#depth},${mp}" )
fi
done < /proc/self/mounts

while IFS=$'\n' read -r filesystem; do
if ! umount "${filesystem#*,}" >/dev/null 2>&1 ; then
zerror "unable to unmount ${filesystem#*,}"
ret=1
fi
done <<<"$( printf '%s\n' "${mounts[@]}" | sort -n -k1 -r )"
fi

return ${ret}
}