Switch from losetup+partprobe to kpartx for Fedora image creation.

Fedora's partprobe does not create devices the same way it does on
Ubuntu. Instead of using partprobe, this patch uses kpartx, which
works on both Fedora and Ubuntu.

Change-Id: Iac5cbac083e423425693c8210cd5d058ce4bce72
This commit is contained in:
Matthew Farrellee 2013-05-28 20:38:51 -04:00
parent 6fe4502058
commit e6608d42da
2 changed files with 14 additions and 4 deletions

View File

@ -31,12 +31,20 @@ if [ ! -f $IMG_PATH/$BASE_IMAGE_TAR ] ; then
RAW_FILE=$(basename $BASE_IMAGE_FILE)
RAW_FILE=${RAW_FILE#.qcow2}.raw
qemu-img convert -f qcow2 -O raw $IMG_PATH/$BASE_IMAGE_FILE $WORKING/$RAW_FILE
LOOPDEV=$(sudo losetup --show -r -f $WORKING/$RAW_FILE)
EACTION="sudo losetup -d $LOOPDEV;$EACTION"
# WARNING: The mattdm image has the root filesystem on the second
# partition (p2). If he changes the image the MAGIC_BIT
# might also need to change.
MAGIC_BIT=p2
# XXX: Parsing stdout is dangerous, would like a better way to discover
# the device used for the image.
# NOTE: On F17 (parted-3.0-10.fc17.x86_64), partprobe of
# /dev/loop0 does not create /dev/loop0p2, while kpartx at
# least creates /dev/mapper/loop0p2.
LOOPDEV=$(sudo kpartx -avr $WORKING/$RAW_FILE | awk "/loop[0-9]+$MAGIC_BIT/ {print \$3}")
EACTION="sudo kpartx -d $WORKING/$RAW_FILE;$EACTION"
trap "$EACTION" EXIT
sudo partprobe $LOOPDEV
mkdir $WORKING/mnt
sudo mount ${LOOPDEV}p2 $WORKING/mnt
sudo mount /dev/mapper/$LOOPDEV $WORKING/mnt
EACTION="sudo umount -f $WORKING/mnt;$EACTION"
trap "$EACTION" EXIT
# Chroot in so that we get the correct uid/gid

View File

@ -25,6 +25,7 @@ ALL ALL=(root) NOPASSWD: /bin/mount -t proc none /tmp/*/mnt/proc
ALL ALL=(root) NOPASSWD: /bin/mount -t sysfs none /tmp/*/mnt/sys
ALL ALL=(root) NOPASSWD: /bin/mount /dev/nbd0* /tmp/*/mnt
ALL ALL=(root) NOPASSWD: /bin/mount /dev/loop* /tmp/*/mnt
ALL ALL=(root) NOPASSWD: /bin/mount /dev/mapper/loop* /tmp/*/mnt
ALL ALL=(root) NOPASSWD: /bin/mv /tmp/*/mnt/* /tmp/*/mnt/*
ALL ALL=(root) NOPASSWD: /bin/mv -t /tmp/*/mnt /tmp/*/built/*
ALL ALL=(root) NOPASSWD: /bin/rm -* /tmp/*/mnt
@ -53,6 +54,7 @@ ALL ALL=(root) NOPASSWD: /sbin/losetup --show -r -f /tmp/*/*.raw
ALL ALL=(root) NOPASSWD: /sbin/losetup --show -f /tmp/*/*.raw
ALL ALL=(root) NOPASSWD: /sbin/losetup -d /dev/loop*
ALL ALL=(root) NOPASSWD: /sbin/partprobe /dev/loop*
ALL ALL=(root) NOPASSWD: /sbin/kpartx -avr /tmp/*/*.raw
ALL ALL=(root) NOPASSWD: /usr/bin/du --block-size=* -x -s /tmp/*/built
ALL ALL=(root) NOPASSWD: /bin/mount -t tmpfs tmpfs /tmp/image.*
ALL ALL=(root) NOPASSWD: /bin/umount -f /tmp/image.*