Compare mount output using base of dirname (#771)

* Compare mount output using base of dirname

If you're building from a bind-mounted directory, the build will
fail as it will find two entries to unmount, but a single unmount
will remove them both causing an error. Adding a space means that
the mountpoint will only match with a single mount entry ; the
expected path, rather than the pre bind-mount.

* Switch to awk instead of mount, grep, cut pipes

Retry unmount 5 times and give up, letting the user know that they need to resolve the issue manually

---------

Co-authored-by: David Peverley <pev@analogue-micro.com>
Co-authored-by: Serge Schneider <serge@raspberrypi.com>
This commit is contained in:
Pev 2024-05-15 15:45:43 +01:00 committed by GitHub
parent 9917c869a7
commit d790fed832
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 7 deletions

View File

@ -83,7 +83,7 @@ cp "$ROOTFS_DIR/etc/rpi-issue" "$INFO_FILE"
dpkg -l --root "$ROOTFS_DIR" dpkg -l --root "$ROOTFS_DIR"
} >> "$INFO_FILE" } >> "$INFO_FILE"
ROOT_DEV="$(mount | grep "${ROOTFS_DIR} " | cut -f1 -d' ')" ROOT_DEV="$(awk "\$2 == \"${ROOTFS_DIR}\" {print \$1}" /etc/mtab)"
unmount "${ROOTFS_DIR}" unmount "${ROOTFS_DIR}"
zerofree "${ROOT_DEV}" zerofree "${ROOT_DEV}"

View File

@ -44,12 +44,15 @@ unmount(){
DIR=$1 DIR=$1
fi fi
while mount | grep -q "$DIR"; do for i in {1..6}; do
local LOCS if awk "\$2 ~ /^${DIR//\//\\/}/ {print \$2}" /etc/mtab | sort -r | xargs -r umount; then
LOCS=$(mount | grep "$DIR" | cut -f 3 -d ' ' | sort -r) break
for loc in $LOCS; do elif [ "$i" -eq 6 ]; then
umount "$loc" log "Failed to unmount ${DIR}. Do not try to delete this directory while it contains mountpoints!"
done return 1
fi
log "Retrying ($i/5)..."
sleep 1
done done
} }
export -f unmount export -f unmount