From 626ca9ad473154a106bb1eea21116a5c13b4e404 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Mon, 23 Mar 2015 10:38:21 +0100 Subject: [PATCH] Run udevadm settle after kpartx -l it may happen that if the system where disk-image-create runs is busy, then the kpartx -l run may leave a stale autodelete loop device. This is because kpartx -l first adds a new loop device, then does the listing and removes the loop device. The latter may not end before the end of the kpartx run, leaving a loop device marked as autodelete. Such kind of loop device will automatically delete itself, so the rm -r $WORKING after sudo umount -f $WORKING/mnt in the EXIT trap will fail because $WORKING does not exist anymore. To prevent this situation, just ask udev to finish its operations, properly removing the (temporary) loop device. Change-Id: I12246f3dbe6b5669e698767682a5a142f803823b --- elements/redhat-common/bin/extract-image | 1 + 1 file changed, 1 insertion(+) diff --git a/elements/redhat-common/bin/extract-image b/elements/redhat-common/bin/extract-image index 799f9f99..e6a361f0 100755 --- a/elements/redhat-common/bin/extract-image +++ b/elements/redhat-common/bin/extract-image @@ -54,6 +54,7 @@ function extract_image() { qemu-img convert -f qcow2 -O raw $CACHED_IMAGE $WORKING/$RAW_FILE ROOT_PARTITON=p$(sudo kpartx -l $WORKING/$RAW_FILE | awk "/loop[0-9]+p/"|wc -l) + sudo udevadm settle # kpartx fails if no /dev/loop* exists, "losetup -f" prints first unused # loop device and creates it if it doesn't exist