File tree Expand file tree Collapse file tree 2 files changed +39
-20
lines changed Expand file tree Collapse file tree 2 files changed +39
-20
lines changed Original file line number Diff line number Diff line change 4
4
cleanup () {
5
5
local mounts mp skip mp_re depth filesystem
6
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
7
+ [ -n " ${mountpoint} " ] && recursive_umount " ${mountpoint} "
26
8
27
9
mount_efivarfs
28
10
Original file line number Diff line number Diff line change @@ -427,7 +427,7 @@ kexec_kernel() {
427
427
then
428
428
zerror " unable to load ${mnt}${kernel} and ${mnt}${initramfs} into memory"
429
429
zerror " ${output} "
430
- umount " ${mnt} "
430
+ recursive_umount " ${mnt} "
431
431
timed_prompt -d 10 \
432
432
-m " $( colorize red ' Unable to load kernel or initramfs into memory' ) " \
433
433
-m " $( colorize orange " ${mnt}${kernel} " ) " \
@@ -2272,3 +2272,40 @@ is_zfs_filesystem() {
2272
2272
2273
2273
return 1
2274
2274
}
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