From 208f8e2530de8689bde6178d203f9bbe68de8b5c Mon Sep 17 00:00:00 2001 From: Alex Yang Date: Wed, 8 Mar 2017 00:30:24 +0800 Subject: Eliminate the exception in image-modify 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 --- tools/daisy-img-modify.sh | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'tools/daisy-img-modify.sh') diff --git a/tools/daisy-img-modify.sh b/tools/daisy-img-modify.sh index 60b60d26..8e025168 100755 --- a/tools/daisy-img-modify.sh +++ b/tools/daisy-img-modify.sh @@ -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 -- cgit 1.2.3-korg