File tree Expand file tree Collapse file tree 2 files changed +39
-23
lines changed
Expand file tree Collapse file tree 2 files changed +39
-23
lines changed Original file line number Diff line number Diff line change 22# vim: softtabstop=2 shiftwidth=2 expandtab
33
44cleanup () {
5- local mounts mp skip mp_re depth filesystem
6-
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
26-
5+ [ -n " ${mountpoint} " ] && recursive_umount " ${mountpoint} "
276 mount_efivarfs
287
298 trap - HUP INT QUIT ABRT EXIT
Original file line number Diff line number Diff 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} " ) " \
@@ -2278,3 +2278,40 @@ is_zfs_filesystem() {
22782278
22792279 return 1
22802280}
2281+
2282+ # arg1: mount point
2283+ # returns: 0 if everything was unmounted, 1 if not
2284+
2285+ recursive_umount () {
2286+ local mounts mountpoint mp skip mp_re depth filesystem ret
2287+
2288+ mountpoint=" ${1} "
2289+ if [ -z " ${mountpoint} " ]; then
2290+ zerror " mountpoint undefined"
2291+ return 1
2292+ fi
2293+
2294+ umount -R " ${mountpoint} " > /dev/null 2>&1 && return 0
2295+
2296+ ret=0
2297+ mounts=()
2298+ mp_re=" ^${mountpoint} "
2299+
2300+ # shellcheck disable=SC2034
2301+ while read -r skip mp skip skip ; do
2302+ if [[ " ${mp} " =~ ${mp_re} ]]; then
2303+ depth=" ${mp// [!\/]/ } "
2304+ mounts+=( " ${# depth} ,${mp} " )
2305+ fi
2306+ done < /proc/self/mounts
2307+
2308+ while IFS=$' \n ' read -r filesystem; do
2309+ if ! umount " ${filesystem#* ,} " > /dev/null 2>&1 ; then
2310+ zerror " unable to unmount ${filesystem#* ,} "
2311+ ret=1
2312+ fi
2313+ done <<< " $( printf '%s\n' " ${mounts[@]} " | sort -n -k1 -r )"
2314+
2315+ return ${ret}
2316+ }
2317+
You can’t perform that action at this time.
0 commit comments