Honor $DIB_IMAGE_SIZE.

The recent change to use loopdev instead of nbd stopped
honoring the DIB_IMAGE_SIZE setting.

This change adds it back, by resizing the image to
DIB_IMAGE_SIZE GB, if specified. If unspecified, it resizes
the image to (actual usage + 20%), as it did before this change.

Change-Id: I69afd9584e644ddacc948619100f153d3d8713a4
This commit is contained in:
Tim Miller 2013-05-06 12:17:42 -07:00
parent a8707cc152
commit 9983245249
3 changed files with 18 additions and 10 deletions

View File

@ -108,19 +108,27 @@ prepare_first_boot
# Free up /mnt
unmount_image
mv $TMP_BUILD_DIR/mnt $TMP_BUILD_DIR/built
# in kb*0.8 - underreport to get a slightly bigger device
_NEEDED_SIZE=$(sudo du --block-size=800 -x -s ${TMP_BUILD_DIR}/built | awk ' { print $1 } ')
truncate -s${_NEEDED_SIZE}K $TMP_IMAGE_PATH
MKFS_OPTS=""
if [ -n "$DIB_IMAGE_SIZE" ]; then
truncate -s${DIB_IMAGE_SIZE}G $TMP_IMAGE_PATH
else
# in kb*0.8 - underreport to get a slightly bigger device
_NEEDED_SIZE=$(sudo du --block-size=800 -x -s ${TMP_BUILD_DIR}/built | awk ' { print $1 } ')
truncate -s${_NEEDED_SIZE}K $TMP_IMAGE_PATH
if [ "$FS_TYPE" = "ext4" ] ; then
# Very conservative to handle images being resized a lot
MKFS_OPTS="-i 4096"
fi
fi
LOOPDEV=$(sudo losetup --show -f $TMP_IMAGE_PATH)
export EXTRA_UNMOUNT="sudo losetup -d $LOOPDEV"
export IMAGE_BLOCK_DEVICE=$LOOPDEV
eval_run_d block-device "IMAGE_BLOCK_DEVICE="
OPTS=""
if [ "$FS_TYPE" = "ext4" ] ; then
# Very conservative to handle images being resized a lot
OPTS="-i 4096"
fi
sudo mkfs $OPTS -t $FS_TYPE -L cloudimg-rootfs ${IMAGE_BLOCK_DEVICE}
sudo mkfs $MKFS_OPTS -t $FS_TYPE -L cloudimg-rootfs ${IMAGE_BLOCK_DEVICE}
mkdir $TMP_BUILD_DIR/mnt
sudo mount ${IMAGE_BLOCK_DEVICE} $TMP_BUILD_DIR/mnt
sudo mv -t $TMP_BUILD_DIR/mnt ${TMP_BUILD_DIR}/built/*

View File

@ -37,7 +37,6 @@ FS_TYPE=${FS_TYPE:-ext4}
# Used to set the file extension only at this stage.
IMAGE_TYPE=${IMAGE_TYPE:-qcow2}
IMAGE_NAME=${IMAGE_NAME:-image}
export DIB_IMAGE_SIZE=${DIB_IMAGE_SIZE:-2} # N.B. This size is in GB
export DIB_NO_TMPFS=${DIB_NO_TMPFS:-0}
# Set via the CLI normally.
# IMAGE_ELEMENT=

View File

@ -37,6 +37,7 @@ ALL ALL=(root) NOPASSWD: /bin/umount -f /tmp/*/mnt/dev
ALL ALL=(root) NOPASSWD: /bin/umount -f /tmp/*/mnt/proc
ALL ALL=(root) NOPASSWD: /bin/umount -f /tmp/*/mnt/sys
ALL ALL=(root) NOPASSWD: /bin/umount -f /tmp/*/mnt/tmp/in_target.d
ALL ALL=(root) NOPASSWD: /sbin/mkfs -t ext4 -L cloudimg-rootfs /dev/loop*
ALL ALL=(root) NOPASSWD: /sbin/mkfs -i 4096 -t ext4 -L cloudimg-rootfs /dev/loop*
ALL ALL=(root) NOPASSWD: /sbin/modprobe nbd max_part=16
ALL ALL=(root) NOPASSWD: /sbin/sfdisk /dev/nbd*