diff --git a/elements/redhat-common/bin/extract-image b/elements/redhat-common/bin/extract-image index e6a361f05..79feb0791 100755 --- a/elements/redhat-common/bin/extract-image +++ b/elements/redhat-common/bin/extract-image @@ -48,12 +48,11 @@ function extract_image() { trap "$EACTION" EXIT echo "Working in $WORKING" - RAW_FILE=$(basename $BASE_IMAGE_FILE) - RAW_FILE=${RAW_FILE%.qcow2}.raw + RAW_FILE=$(mktemp --tmpdir=$WORKING XXXXXX.raw) - qemu-img convert -f qcow2 -O raw $CACHED_IMAGE $WORKING/$RAW_FILE + qemu-img convert -f qcow2 -O raw $CACHED_IMAGE $RAW_FILE - ROOT_PARTITON=p$(sudo kpartx -l $WORKING/$RAW_FILE | awk "/loop[0-9]+p/"|wc -l) + ROOT_PARTITON=p$(sudo kpartx -l $RAW_FILE | awk "/loop[0-9]+p/"|wc -l) sudo udevadm settle # kpartx fails if no /dev/loop* exists, "losetup -f" prints first unused @@ -62,7 +61,7 @@ function extract_image() { # XXX: Parsing stdout is dangerous, would like a better way to discover # the device used for the image. - ROOT_LOOPDEV=$(sudo kpartx -av $WORKING/$RAW_FILE | \ + ROOT_LOOPDEV=$(sudo kpartx -av $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 @@ -72,7 +71,7 @@ function extract_image() { echo "Error: Could not find /dev/mapper/$ROOT_LOOPDEV" exit 1 fi - EACTION="sudo kpartx -d $WORKING/$RAW_FILE ; $EACTION" + EACTION="sudo kpartx -d $RAW_FILE ; $EACTION" trap "$EACTION" EXIT mkdir $WORKING/mnt sudo mount /dev/mapper/$ROOT_LOOPDEV $WORKING/mnt diff --git a/elements/rhel/root.d/10-rhel-cloud-image b/elements/rhel/root.d/10-rhel-cloud-image index 90771df94..1571249fd 100755 --- a/elements/rhel/root.d/10-rhel-cloud-image +++ b/elements/rhel/root.d/10-rhel-cloud-image @@ -31,13 +31,12 @@ else WORKING=$(mktemp -d) EACTION="rm -r $WORKING" trap "$EACTION" EXIT - RAW_FILE=$(basename $BASE_IMAGE_FILE) - RAW_FILE=${RAW_FILE%.qcow2}.raw - qemu-img convert -f qcow2 -O raw $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE $WORKING/$RAW_FILE + RAW_FILE=$(mktemp --tmpdir=$WORKING XXXXXX.raw) + qemu-img convert -f qcow2 -O raw $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE $RAW_FILE MAGIC_BIT=p1 # 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}") + LOOPDEV=$(sudo kpartx -av $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 @@ -48,7 +47,7 @@ else echo "Error: Could not find /dev/mapper/$LOOPDEV" exit 1 fi - EACTION="sudo kpartx -d $WORKING/$RAW_FILE;$EACTION" + EACTION="sudo kpartx -d $RAW_FILE;$EACTION" trap "$EACTION" EXIT mkdir $WORKING/mnt sudo mount /dev/mapper/$LOOPDEV $WORKING/mnt diff --git a/elements/ubuntu-core/root.d/10-cache-ubuntu-image b/elements/ubuntu-core/root.d/10-cache-ubuntu-image index ea7062317..550fdc2e8 100755 --- a/elements/ubuntu-core/root.d/10-cache-ubuntu-image +++ b/elements/ubuntu-core/root.d/10-cache-ubuntu-image @@ -52,13 +52,12 @@ else WORKING=$(mktemp -d) EACTION="rm -r $WORKING" trap "$EACTION" EXIT - RAW_FILE=$(basename $BASE_IMAGE_FILE) - RAW_FILE=${RAW_FILE%.img}.raw - qemu-img convert -f qcow2 -O raw $CACHED_FILE $WORKING/$RAW_FILE + RAW_FILE=$(mktemp --tmpdir=$WORKING XXXXXX.raw) + qemu-img convert -f qcow2 -O raw $CACHED_FILE $RAW_FILE MAGIC_BIT=p1 # 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}") + LOOPDEV=$(sudo kpartx -av $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 @@ -69,7 +68,7 @@ else echo "Error: Could not find /dev/mapper/$LOOPDEV" exit 1 fi - EACTION="sudo kpartx -d $WORKING/$RAW_FILE;$EACTION" + EACTION="sudo kpartx -d $RAW_FILE;$EACTION" trap "$EACTION" EXIT mkdir $WORKING/mnt sudo mount /dev/mapper/$LOOPDEV $WORKING/mnt