use a single partitioned loop device (#641)

This commit is contained in:
rfc6919
2022-11-11 19:56:04 +11:00
committed by GitHub
parent c3083ecd50
commit 1d13a292a7
3 changed files with 20 additions and 64 deletions

View File

@ -57,19 +57,15 @@ export -f unmount
unmount_image(){
sync
sleep 1
local LOOP_DEVICES
LOOP_DEVICES=$(losetup --list | grep "$(basename "${1}")" | cut -f1 -d' ')
for LOOP_DEV in ${LOOP_DEVICES}; do
if [ -n "${LOOP_DEV}" ]; then
local MOUNTED_DIR
MOUNTED_DIR=$(mount | grep "$(basename "${LOOP_DEV}")" | head -n 1 | cut -f 3 -d ' ')
if [ -n "${MOUNTED_DIR}" ] && [ "${MOUNTED_DIR}" != "/" ]; then
unmount "$(dirname "${MOUNTED_DIR}")"
LOOP_DEVICE=$(losetup --list | grep "$1" | cut -f1 -d' ')
if [ -n "$LOOP_DEVICE" ]; then
for part in "$LOOP_DEVICE"p*; do
if DIR=$(findmnt -n -o target -S "$part"); then
unmount "$DIR"
fi
sleep 1
losetup -d "${LOOP_DEV}"
fi
done
done
losetup -d "$LOOP_DEVICE"
fi
}
export -f unmount_image