Merge "Use shorter temporary file names for kpartx"

This commit is contained in:
Jenkins 2015-04-23 03:51:48 +00:00 committed by Gerrit Code Review
commit 97c2432635
3 changed files with 13 additions and 16 deletions

View File

@ -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

View File

@ -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

View File

@ -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