Skip to content

Commit ce45f6d

Browse files
committed
zfsbootmenu: add and use recursive_umount function
1 parent 754d337 commit ce45f6d

File tree

2 files changed

+39
-20
lines changed

2 files changed

+39
-20
lines changed

zfsbootmenu/bin/zfs-chroot

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,7 @@
44
cleanup() {
55
local mounts mp skip mp_re depth filesystem
66

7-
if [ -n "${mountpoint}" ]; then
8-
if ! umount -R "${mountpoint}" >/dev/null 2>&1 ; then
9-
# thanks, busybox
10-
mounts=()
11-
mp_re="^${mountpoint}"
12-
13-
# shellcheck disable=SC2034
14-
while read -r skip mp skip skip ; do
15-
if [[ "${mp}" =~ ${mp_re} ]]; then
16-
depth="${mp//[!\/]/}"
17-
mounts+=( "${#depth},${mp}" )
18-
fi
19-
done < /proc/self/mounts
20-
21-
while IFS=$'\n' read -r filesystem; do
22-
umount "${filesystem#*,}" || zerror "unable to unmount ${filesystem#*,}"
23-
done <<<"$( printf '%s\n' "${mounts[@]}" | sort -n -k1 -r )"
24-
fi
25-
fi
7+
[ -n "${mountpoint}" ] && recursive_umount "${mountpoint}"
268

279
mount_efivarfs
2810

zfsbootmenu/lib/zfsbootmenu-core.sh

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ kexec_kernel() {
427427
then
428428
zerror "unable to load ${mnt}${kernel} and ${mnt}${initramfs} into memory"
429429
zerror "${output}"
430-
umount "${mnt}"
430+
recursive_umount "${mnt}"
431431
timed_prompt -d 10 \
432432
-m "$( colorize red 'Unable to load kernel or initramfs into memory' )" \
433433
-m "$( colorize orange "${mnt}${kernel}" )" \
@@ -2272,3 +2272,40 @@ is_zfs_filesystem() {
22722272

22732273
return 1
22742274
}
2275+
2276+
# arg1: mount point
2277+
# returns: 0 if everything was unmounted, 1 if not
2278+
2279+
recursive_umount() {
2280+
local mounts mountpoint mp skip mp_re depth filesystem ret
2281+
2282+
mountpoint="${1}"
2283+
if [ -z "${mountpoint}" ]; then
2284+
zerror "mountpoint undefined"
2285+
return 1
2286+
fi
2287+
2288+
ret=0
2289+
if ! umount -R "${mountpoint}" >/dev/null 2>&1 ; then
2290+
mounts=()
2291+
mp_re="^${mountpoint}"
2292+
2293+
# shellcheck disable=SC2034
2294+
while read -r skip mp skip skip ; do
2295+
if [[ "${mp}" =~ ${mp_re} ]]; then
2296+
depth="${mp//[!\/]/}"
2297+
mounts+=( "${#depth},${mp}" )
2298+
fi
2299+
done < /proc/self/mounts
2300+
2301+
while IFS=$'\n' read -r filesystem; do
2302+
if ! umount "${filesystem#*,}" >/dev/null 2>&1 ; then
2303+
zerror "unable to unmount ${filesystem#*,}"
2304+
ret=1
2305+
fi
2306+
done <<<"$( printf '%s\n' "${mounts[@]}" | sort -n -k1 -r )"
2307+
fi
2308+
2309+
return ${ret}
2310+
}
2311+

0 commit comments

Comments
 (0)