Patchwork mkefidisk: Attempt to automatically unmount target device

login
register
mail settings
Submitter Darren Hart
Date April 25, 2013, 5:23 p.m.
Message ID <8e2bf476da78d8eaef1606eb8516c45520c3f996.1366910631.git.dvhart@linux.intel.com>
Download mbox | patch
Permalink /patch/48905/
State Accepted
Commit d853d5b6d011088ca1078283a6c7bfd60f47e7a2
Headers show

Comments

Darren Hart - April 25, 2013, 5:23 p.m.
With automounters abounding it makes more sense to attempt to unmount
the device rather than abort, just like ddimage does.

Signed-off-by: Darren Hart <dvhart@linux.intel.com>
---
 scripts/contrib/mkefidisk.sh | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

Patch

diff --git a/scripts/contrib/mkefidisk.sh b/scripts/contrib/mkefidisk.sh
index acadd49..741c3ab 100755
--- a/scripts/contrib/mkefidisk.sh
+++ b/scripts/contrib/mkefidisk.sh
@@ -102,10 +102,14 @@  fi
 #
 grep -q $DEVICE /proc/mounts
 if [ $? -eq 0 ]; then
-	echo "ERROR: $DEVICE partitions mounted:"
-	grep $DEVICE /proc/mounts | cut -f 1 -d " "
-	echo "Unmount the partitions listed and try again."
-	exit 1
+	echo -n "$DEVICE listed in /proc/mounts, attempting to unmount..."
+	umount $DEVICE* 2>/dev/null
+	grep -q $DEVICE /proc/mounts
+	if [ $? -eq 0 ]; then
+		echo "FAILED"
+		exit 1
+	fi
+	echo "OK"
 fi
 
 
@@ -153,6 +157,7 @@  echo "Boot partition size:   $BOOT_SIZE MB ($BOOTFS)"
 echo "ROOTFS partition size: $ROOTFS_SIZE MB ($ROOTFS)"
 echo "Swap partition size:   $SWAP_SIZE MB ($SWAP)"
 echo "*****************"
+
 echo "Deleting partition table on $DEVICE ..."
 dd if=/dev/zero of=$DEVICE bs=512 count=2