From ea4063095dfec1075ea9e2a2f131594c3a962eb0 Mon Sep 17 00:00:00 2001 From: Erick Cardona Date: Wed, 14 Feb 2018 14:27:40 -0600 Subject: [PATCH] image-builder: Allow to specify root partition free space There is no way to specify the remaining free space of the root partition. It can vary depending on the upper bound size of the image aligned to 128MB and the size of the root filesystem. The following patch allow the user to specify that at least a certain amount of space (defined in MB) will be kept in the root partition. Fixes: #45 Signed-off-by: Erick Cardona --- image-builder/image_builder.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/image-builder/image_builder.sh b/image-builder/image_builder.sh index d604fe3c9f..c9561754a5 100755 --- a/image-builder/image_builder.sh +++ b/image-builder/image_builder.sh @@ -57,6 +57,7 @@ Options: -h Show this help -o path to generate image file ENV: IMAGE -s Image size in MB ENV: IMG_SIZE + -r Free space of the root partition in MB ENV: ROOT_FREE_SPACE Extra environment variables: AGENT_BIN: use it to change the expected agent binary name @@ -79,11 +80,12 @@ MEM_BOUNDARY=128 MAX_ATTEMPTS=5 ATTEMPT_NUM=0 -while getopts "ho:s:f:" opt +while getopts "ho:r:s:f:" opt do case "$opt" in h) usage ;; o) IMAGE="${OPTARG}" ;; + r) ROOT_FREE_SPACE="${OPTARG}" ;; s) IMG_SIZE=${OPTARG} if [ ${IMG_SIZE} -le 0 ]; then die "Image size has to be greater than 0 MB." @@ -162,6 +164,11 @@ calculate_img_size() { IMG_SIZE=${IMG_SIZE:-$MEM_BOUNDARY} align_memory + if [ -n "$ROOT_FREE_SPACE" ] && [ "$IMG_SIZE" -gt "$ROOTFS_SIZE" ]; then + info "Ensure that root partition has at least ${ROOT_FREE_SPACE}MB of free space" + IMG_SIZE=$(($IMG_SIZE + $ROOT_FREE_SPACE)) + fi + } # Cleanup @@ -244,4 +251,4 @@ OK "rootfs copied" cleanup -info "Image created. Size: ${IMG_SIZE}MB." +info "Image created. Virtual size: ${IMG_SIZE}MB."