diff --git a/elements/fedora/root.d/10-fedora-cloud-image b/elements/fedora/root.d/10-fedora-cloud-image index 14e4ac728..46a8dfe14 100755 --- a/elements/fedora/root.d/10-fedora-cloud-image +++ b/elements/fedora/root.d/10-fedora-cloud-image @@ -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 diff --git a/sudoers.d/img-build-sudoers b/sudoers.d/img-build-sudoers index 281f7c2e1..7090044ae 100644 --- a/sudoers.d/img-build-sudoers +++ b/sudoers.d/img-build-sudoers @@ -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.*