Eliminate the exception in image-modify 79/29979/3
authorAlex Yang <yangyang1@zte.com.cn>
Tue, 7 Mar 2017 16:30:24 +0000 (00:30 +0800)
committerAlex Yang <yangyang1@zte.com.cn>
Thu, 9 Mar 2017 15:14:11 +0000 (23:14 +0800)
Sometimes kpartx fails when it deletes the partition device mappings
because of the automatic mounting to /run/media/root/xxxx. So umounting
and removing forcibly are needed.

Change-Id: Ic8a19ef9139adb9c0c5c4bead0ae0ffbd92f24b8
Signed-off-by: Alex Yang <yangyang1@zte.com.cn>
tools/daisy-img-modify.sh

index 60b60d2..8e02516 100755 (executable)
@@ -135,6 +135,16 @@ install_utils()
     fi
 }
 
+# Eliminate exceptions
+eliminate()
+{
+    if [ -b /dev/mapper/$loopdevice ]; then
+        umount /dev/mapper/$loopdevice || true
+        dmsetup remove $loopdevice || true
+    fi
+    return 0
+}
+
 # resize image
 resize() {
     install_utils
@@ -149,7 +159,7 @@ resize() {
     fdisk -l /dev/${loopdevice:0:5} || true
     growpart /dev/${loopdevice:0:5} 1
     dmsetup clear $loopdevice
-    kpartx -dv $raw_imgfile
+    kpartx -dv $raw_imgfile || eliminate
 }
 
 # mount image
@@ -193,7 +203,7 @@ cleanup() {
     mount | grep $mountdir/proc && umount $mountdir/proc
     mount | grep $mountdir && umount $mountdir
     if [ -f $raw_imgfile ]; then
-        kpartx -dv $raw_imgfile || true
+        kpartx -dv $raw_imgfile || eliminate
     fi
     rm -f $raw_imgfile
     rm -rf $mountdir