Merge "Use shorter temporary file names for kpartx"
This commit is contained in:
commit
97c2432635
@ -48,12 +48,11 @@ function extract_image() {
|
|||||||
trap "$EACTION" EXIT
|
trap "$EACTION" EXIT
|
||||||
echo "Working in $WORKING"
|
echo "Working in $WORKING"
|
||||||
|
|
||||||
RAW_FILE=$(basename $BASE_IMAGE_FILE)
|
RAW_FILE=$(mktemp --tmpdir=$WORKING XXXXXX.raw)
|
||||||
RAW_FILE=${RAW_FILE%.qcow2}.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
|
sudo udevadm settle
|
||||||
|
|
||||||
# kpartx fails if no /dev/loop* exists, "losetup -f" prints first unused
|
# 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
|
# XXX: Parsing stdout is dangerous, would like a better way to discover
|
||||||
# the device used for the image.
|
# 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}")
|
awk "/loop[0-9]+$ROOT_PARTITON/ {print \$3}")
|
||||||
# If running inside Docker, make our nodes manually, because udev will not be working.
|
# If running inside Docker, make our nodes manually, because udev will not be working.
|
||||||
if [ -f /.dockerenv ]; then
|
if [ -f /.dockerenv ]; then
|
||||||
@ -72,7 +71,7 @@ function extract_image() {
|
|||||||
echo "Error: Could not find /dev/mapper/$ROOT_LOOPDEV"
|
echo "Error: Could not find /dev/mapper/$ROOT_LOOPDEV"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
EACTION="sudo kpartx -d $WORKING/$RAW_FILE ; $EACTION"
|
EACTION="sudo kpartx -d $RAW_FILE ; $EACTION"
|
||||||
trap "$EACTION" EXIT
|
trap "$EACTION" EXIT
|
||||||
mkdir $WORKING/mnt
|
mkdir $WORKING/mnt
|
||||||
sudo mount /dev/mapper/$ROOT_LOOPDEV $WORKING/mnt
|
sudo mount /dev/mapper/$ROOT_LOOPDEV $WORKING/mnt
|
||||||
|
@ -31,13 +31,12 @@ else
|
|||||||
WORKING=$(mktemp -d)
|
WORKING=$(mktemp -d)
|
||||||
EACTION="rm -r $WORKING"
|
EACTION="rm -r $WORKING"
|
||||||
trap "$EACTION" EXIT
|
trap "$EACTION" EXIT
|
||||||
RAW_FILE=$(basename $BASE_IMAGE_FILE)
|
RAW_FILE=$(mktemp --tmpdir=$WORKING XXXXXX.raw)
|
||||||
RAW_FILE=${RAW_FILE%.qcow2}.raw
|
qemu-img convert -f qcow2 -O raw $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE $RAW_FILE
|
||||||
qemu-img convert -f qcow2 -O raw $DIB_IMAGE_CACHE/$BASE_IMAGE_FILE $WORKING/$RAW_FILE
|
|
||||||
MAGIC_BIT=p1
|
MAGIC_BIT=p1
|
||||||
# NOTE: On RHEL, partprobe of /dev/loop0 does not create /dev/loop0p2,
|
# NOTE: On RHEL, partprobe of /dev/loop0 does not create /dev/loop0p2,
|
||||||
# while kpartx at least creates /dev/mapper/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 running inside Docker, make our nodes manually, because udev will not be working.
|
||||||
if [ -f /.dockerenv ]; then
|
if [ -f /.dockerenv ]; then
|
||||||
sudo dmsetup --noudevsync mknodes
|
sudo dmsetup --noudevsync mknodes
|
||||||
@ -48,7 +47,7 @@ else
|
|||||||
echo "Error: Could not find /dev/mapper/$LOOPDEV"
|
echo "Error: Could not find /dev/mapper/$LOOPDEV"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
EACTION="sudo kpartx -d $WORKING/$RAW_FILE;$EACTION"
|
EACTION="sudo kpartx -d $RAW_FILE;$EACTION"
|
||||||
trap "$EACTION" EXIT
|
trap "$EACTION" EXIT
|
||||||
mkdir $WORKING/mnt
|
mkdir $WORKING/mnt
|
||||||
sudo mount /dev/mapper/$LOOPDEV $WORKING/mnt
|
sudo mount /dev/mapper/$LOOPDEV $WORKING/mnt
|
||||||
|
@ -52,13 +52,12 @@ else
|
|||||||
WORKING=$(mktemp -d)
|
WORKING=$(mktemp -d)
|
||||||
EACTION="rm -r $WORKING"
|
EACTION="rm -r $WORKING"
|
||||||
trap "$EACTION" EXIT
|
trap "$EACTION" EXIT
|
||||||
RAW_FILE=$(basename $BASE_IMAGE_FILE)
|
RAW_FILE=$(mktemp --tmpdir=$WORKING XXXXXX.raw)
|
||||||
RAW_FILE=${RAW_FILE%.img}.raw
|
qemu-img convert -f qcow2 -O raw $CACHED_FILE $RAW_FILE
|
||||||
qemu-img convert -f qcow2 -O raw $CACHED_FILE $WORKING/$RAW_FILE
|
|
||||||
MAGIC_BIT=p1
|
MAGIC_BIT=p1
|
||||||
# NOTE: On RHEL, partprobe of /dev/loop0 does not create /dev/loop0p2,
|
# NOTE: On RHEL, partprobe of /dev/loop0 does not create /dev/loop0p2,
|
||||||
# while kpartx at least creates /dev/mapper/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 running inside Docker, make our nodes manually, because udev will not be working.
|
||||||
if [ -f /.dockerenv ]; then
|
if [ -f /.dockerenv ]; then
|
||||||
sudo dmsetup --noudevsync mknodes
|
sudo dmsetup --noudevsync mknodes
|
||||||
@ -69,7 +68,7 @@ else
|
|||||||
echo "Error: Could not find /dev/mapper/$LOOPDEV"
|
echo "Error: Could not find /dev/mapper/$LOOPDEV"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
EACTION="sudo kpartx -d $WORKING/$RAW_FILE;$EACTION"
|
EACTION="sudo kpartx -d $RAW_FILE;$EACTION"
|
||||||
trap "$EACTION" EXIT
|
trap "$EACTION" EXIT
|
||||||
mkdir $WORKING/mnt
|
mkdir $WORKING/mnt
|
||||||
sudo mount /dev/mapper/$LOOPDEV $WORKING/mnt
|
sudo mount /dev/mapper/$LOOPDEV $WORKING/mnt
|
||||||
|
Loading…
Reference in New Issue
Block a user