image: custom guest rootfs image file size alignment

The Guest rootfs image file size is aligned up to 128M boundary,
since commmit 2b0d5b2. This change allows users to use a custom
alignment value - e.g., to align up to 2M, users will be able to
specify IMAGE_SIZE_ALIGNMENT_MB=2 for image_builder.sh.

Signed-off-by: Dan Mihai <dmihai@microsoft.com>
This commit is contained in:
Dan Mihai 2025-05-29 20:51:24 +00:00
parent c575048aa7
commit 65385a5bf9
2 changed files with 5 additions and 5 deletions

View File

@ -12,6 +12,7 @@ set -o pipefail
DOCKER_RUNTIME=${DOCKER_RUNTIME:-runc}
MEASURED_ROOTFS=${MEASURED_ROOTFS:-no}
IMAGE_SIZE_ALIGNMENT_MB=${IMAGE_SIZE_ALIGNMENT_MB:-128}
#For cross build
CROSS_BUILD=${CROSS_BUILD:-false}
@ -54,9 +55,6 @@ AGENT_INIT=${AGENT_INIT:-no}
SELINUX=${SELINUX:-no}
SELINUXFS="/sys/fs/selinux"
# Align image to 128M
readonly mem_boundary_mb=128
# shellcheck source=../scripts/lib.sh
source "${lib_file}"
@ -178,6 +176,7 @@ build_with_container() {
--env TARGET_ARCH="${TARGET_ARCH}" \
--env USER="$(id -u)" \
--env GROUP="$(id -g)" \
--env IMAGE_SIZE_ALIGNMENT_MB="${IMAGE_SIZE_ALIGNMENT_MB}" \
-v /dev:/dev \
-v "${script_dir}":"/osbuilder" \
-v "${script_dir}/../scripts":"/scripts" \
@ -308,9 +307,9 @@ calculate_img_size() {
img_size="$((img_size + root_free_space_mb))"
fi
remaining="$((img_size % mem_boundary_mb))"
remaining="$((img_size % ${IMAGE_SIZE_ALIGNMENT_MB}))"
if [ "${remaining}" != "0" ]; then
img_size=$((img_size + mem_boundary_mb - remaining))
img_size=$((img_size + ${IMAGE_SIZE_ALIGNMENT_MB} - remaining))
fi
echo "${img_size}"

View File

@ -112,6 +112,7 @@ REPO_URL_X86_64="${REPO_URL_X86_64:-}"
REPO_COMPONENTS="${REPO_COMPONENTS:-}"
AGENT_POLICY="${AGENT_POLICY:-yes}"
RUNTIME_CHOICE="${RUNTIME_CHOICE:-both}"
IMAGE_SIZE_ALIGNMENT_MB=${IMAGE_SIZE_ALIGNMENT_MB:-}
docker run \
-v $HOME/.docker:/root/.docker \