From 1f029607434e389697f7c70f077bef820fd308b1 Mon Sep 17 00:00:00 2001 From: Gregory Haynes Date: Tue, 31 Mar 2015 04:52:08 +0000 Subject: [PATCH] Fix image size to fit filesystem journal Our logic to determine needed image size doesnt fully account for the in-filesystem journal. This only shows up when creating images that are very small relative to the FS journal size. Change-Id: Ic3c2bcd31ec4fee6bcd9f67767842eb3fbe20d3a --- bin/disk-image-create | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/bin/disk-image-create b/bin/disk-image-create index c96edec..8a9ee7f 100755 --- a/bin/disk-image-create +++ b/bin/disk-image-create @@ -230,15 +230,18 @@ else # Rounding down size so that is is a multiple of 64, works around a bug in # qemu-img that may occur when compressing raw images that aren't a multiple # of 64k. https://bugs.launchpad.net/ubuntu/+source/linux/+bug/1180021 - _NEEDED_SIZE=$(sudo du --block-size=600 -x -s ${TMP_BUILD_DIR}/built | \ - awk ' { print $1 - ( $1 % 64) } ') - truncate -s${_NEEDED_SIZE}K $TMP_IMAGE_PATH + du_size=$(sudo du --block-size=600 -x -s ${TMP_BUILD_DIR}/built |\ + awk ' { print $1 }') if [ "$FS_TYPE" = "ext4" ] ; then # Very conservative to handle images being resized a lot - # Without -J option specified, default journal size will be set to 32M - # and online resize will be failed with error of needs too many credits. + # We set journal size to 64M so our journal is large enough when we + # perform an FS resize. MKFS_OPTS="-i 4096 -J size=64 $MKFS_OPTS" + du_size=$(( $du_size + 65536 )) fi + + _NEEDED_SIZE=$(echo "$du_size" | awk ' { print $1 + 64 - ( $1 % 64) } ') + truncate -s${_NEEDED_SIZE}K $TMP_IMAGE_PATH fi if [ -n "$MAX_ONLINE_RESIZE" ]; then