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} " ) " \
@@ -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+
You can’t perform that action at this time.
0 commit comments