diff --git a/elements/redhat-common/bin/extract-image b/elements/redhat-common/bin/extract-image index e394cc3a..c9e6907a 100755 --- a/elements/redhat-common/bin/extract-image +++ b/elements/redhat-common/bin/extract-image @@ -3,7 +3,6 @@ # Intended to be called from the root.d cloud-image script as follows: # $TMP_HOOKS_PATH/bin/extract-image $BASE_IMAGE_FILE $BASE_IMAGE_TAR $IMAGE_LOCATION $CACHED_IMAGE - set -eu set -o pipefail @@ -64,6 +63,10 @@ function extract_image() { # the device used for the image. ROOT_LOOPDEV=$(sudo kpartx -av $WORKING/$RAW_FILE | \ awk "/loop[0-9]+$ROOT_PARTITON/ {print \$3}") + # If running inside Docker, make our nodes manually, because udev will not be working. + if [ -f /.dockerenv ]; then + sudo dmsetup --noudevsync mknodes + fi if ! timeout 5 sh -c "while ! [ -e /dev/mapper/$ROOT_LOOPDEV ]; do sleep 1; done"; then echo "Error: Could not find /dev/mapper/$ROOT_LOOPDEV" exit 1 diff --git a/elements/rhel/root.d/10-rhel-cloud-image b/elements/rhel/root.d/10-rhel-cloud-image index 2867e36a..862ee2da 100755 --- a/elements/rhel/root.d/10-rhel-cloud-image +++ b/elements/rhel/root.d/10-rhel-cloud-image @@ -35,6 +35,10 @@ else # NOTE: On RHEL, partprobe of /dev/loop0 does not create /dev/loop0p2, # while kpartx at least creates /dev/mapper/loop0p2. LOOPDEV=$(sudo kpartx -av $WORKING/$RAW_FILE | awk "/loop[0-9]+$MAGIC_BIT/ {print \$3}") + # If running inside Docker, make our nodes manually, because udev will not be working. + if [ -f /.dockerenv ]; then + sudo dmsetup --noudevsync mknodes + fi export LOOPDEV=$LOOPDEV echo "Loop device is set to: $LOOPDEV" if ! timeout 5 sh -c "while ! [ -e /dev/mapper/$LOOPDEV ]; do sleep 1; done"; then diff --git a/elements/vm/block-device.d/10-partition b/elements/vm/block-device.d/10-partition index 2608e004..33526161 100755 --- a/elements/vm/block-device.d/10-partition +++ b/elements/vm/block-device.d/10-partition @@ -22,8 +22,15 @@ sudo udevadm settle # If the partition isn't under /dev/loop*p1, create it with kpartx DM= if [ ! -e "${IMAGE_BLOCK_DEVICE}p1" ]; then - sudo kpartx -asv $TMP_IMAGE_PATH DM=${IMAGE_BLOCK_DEVICE/#\/dev/\/dev\/mapper} + # If running inside Docker, make our nodes manually, because udev will not be working. + if [ -f /.dockerenv ]; then + # kpartx cannot run in sync mode in docker. + sudo kpartx -av $TMP_IMAGE_PATH + sudo dmsetup --noudevsync mknodes + else + sudo kpartx -asv $TMP_IMAGE_PATH + fi fi if [ -n "$DM" ]; then diff --git a/lib/common-functions b/lib/common-functions index f00ae077..2f0346fa 100644 --- a/lib/common-functions +++ b/lib/common-functions @@ -211,7 +211,7 @@ function detach_loopback() { loopdev_name=$(echo $loopdev | sed 's/\/dev\///g') mapper_name=$(sudo dmsetup ls | grep $loopdev_name | awk '{ print $1 }') if [ "$mapper_name" ]; then - sudo dmsetup remove $mapper_name + sudo dmsetup --noudevsync remove $mapper_name fi # loopback dev may be tied up a bit by udev events triggered by partition events