diff --git a/lib/common-functions b/lib/common-functions index f3afe39e2..4873d7817 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -275,3 +275,12 @@ function mount_proc_dev_sys () { sudo mount -t sysfs none $TMP_MOUNT_PATH/sys } +function unmount_dir () { + local pattern="$1" mnts="" + if [ -n "$pattern" ]; then + mnts=`awk '{print $2}' < /proc/mounts | grep "^$pattern" | sort -r` + fi + if [ -n "$mnts" ]; then + sudo umount -fl $mnts || true + fi +} diff --git a/lib/ramdisk-functions b/lib/ramdisk-functions index 3646585da..aaa269839 100644 --- a/lib/ramdisk-functions +++ b/lib/ramdisk-functions @@ -25,7 +25,14 @@ function fullpath() { } function cleanup () { - sudo umount -f $TMP_BUILD_DIR || true + unmount_dir "$TMP_BUILD_DIR/mnt" + if [ -f "$TMP_IMAGE_PATH" ]; then + loopdev=`sudo losetup -j "$TMP_IMAGE_PATH" | cut -d: -f1` + if [ -n "$loopdev" ]; then + detach_loopback "$loopdev" + fi + fi + unmount_dir "$TMP_BUILD_DIR" rm -rf --one-file-system "$TMP_BUILD_DIR" }