mkefidisk: Unmount after partitioning

Submitted by Darren Hart on April 25, 2013, 9:27 p.m.

Details

Message ID 8f406a3b7d0effba9c2cf67191453b6662d6e0b3.1366925249.git.dvhart@linux.intel.com
State Accepted
Commit f1854e458e5e77806b1fc837033500fa91272261
Headers show

Commit Message

Darren Hart April 25, 2013, 9:27 p.m.
Some automounters are rather overzealous and like to mount things
immediately after partitioning. This can happen if the disk is being
reused and the partitions align exactly with the existing partitions
which have already been formatted. Move the unmount code into a function
and call it before and after partitioning.

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

Patch hide | download patch | download mbox

diff --git a/scripts/contrib/mkefidisk.sh b/scripts/contrib/mkefidisk.sh
index 741c3ab..0c15104 100755
--- a/scripts/contrib/mkefidisk.sh
+++ b/scripts/contrib/mkefidisk.sh
@@ -71,6 +71,20 @@  function device_details() {
 	echo ""
 }
 
+function unmount_device() {
+	grep -q $DEVICE /proc/mounts
+	if [ $? -eq 0 ]; then
+		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
+}
+
 
 #
 # Parse and validate arguments
@@ -100,17 +114,7 @@  fi
 #
 # Check if any $DEVICE partitions are mounted
 #
-grep -q $DEVICE /proc/mounts
-if [ $? -eq 0 ]; then
-	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
+unmount_device
 
 
 #
@@ -183,6 +187,12 @@  parted $DEVICE print
 
 
 #
+# Check if any $DEVICE partitions are mounted after partitioning
+#
+unmount_device
+
+
+#
 # Format $DEVICE partitions
 #
 echo ""