summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorSerge Schneider <serge@raspberrypi.com>2024-05-15 15:52:53 +0100
committerSerge Schneider <serge@raspberrypi.com>2024-05-15 15:52:53 +0100
commit0755b07f068b3913e72e3481fb03767713777538 (patch)
tree6ed3fe8af037c0f0ee3f66b54655c9a9033ec858 /scripts
parent97aa847ea8962303a418ba4c57ff0394e43ccde9 (diff)
parentfb48183f0d49df3d069f0086263d829efa899c70 (diff)
Merge branch 'master' into arm64
Diffstat (limited to 'scripts')
-rw-r--r--scripts/common24
1 files changed, 15 insertions, 9 deletions
diff --git a/scripts/common b/scripts/common
index f84edc3..5a72ead 100644
--- a/scripts/common
+++ b/scripts/common
@@ -45,20 +45,26 @@ unmount(){
DIR=$1
fi
- while mount | grep -q "$DIR"; do
- local LOCS
- LOCS=$(mount | grep "$DIR" | cut -f 3 -d ' ' | sort -r)
- for loc in $LOCS; do
- umount "$loc"
- done
+ for i in {1..6}; do
+ if awk "\$2 ~ /^${DIR//\//\\/}/ {print \$2}" /etc/mtab | sort -r | xargs -r umount; then
+ break
+ elif [ "$i" -eq 6 ]; then
+ log "Failed to unmount ${DIR}. Do not try to delete this directory while it contains mountpoints!"
+ return 1
+ fi
+ log "Retrying ($i/5)..."
+ sleep 1
done
}
export -f unmount
unmount_image(){
- sync
- sleep 1
- LOOP_DEVICE=$(losetup --list | grep "$1" | cut -f1 -d' ')
+ if command -v udevadm >/dev/null 2>&1; then
+ udevadm settle 10
+ else
+ sleep 1
+ fi
+ LOOP_DEVICE=$(losetup -n -O NAME -j "$1")
if [ -n "$LOOP_DEVICE" ]; then
for part in "$LOOP_DEVICE"p*; do
if DIR=$(findmnt -n -o target -S "$part"); then