From bfcee91164ae1f21dd035e3d7b5b9dc6a5d59bfe Mon Sep 17 00:00:00 2001 From: Yujia Qiao Date: Thu, 2 Sep 2021 15:28:41 +0800 Subject: [PATCH] osbuilder: fix inconsistent calculation of fs size This patch fixes inconsistent calculations of the rootfs size. For `du` and `df`, `-B 1MB` is different from `-BM`. The former is the power of 1000, and the latter is the power of 1024. So comparing them doesn't make sense. The bug may result in a larger image than needed. Fixes: #2560 Signed-off-by: Yujia Qiao --- tools/osbuilder/image-builder/image_builder.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/osbuilder/image-builder/image_builder.sh b/tools/osbuilder/image-builder/image_builder.sh index 559931df30..5883ad2a40 100755 --- a/tools/osbuilder/image-builder/image_builder.sh +++ b/tools/osbuilder/image-builder/image_builder.sh @@ -242,7 +242,7 @@ calculate_required_disk_size() { local fs_type="$2" local block_size="$3" - readonly rootfs_size_mb=$(du -B 1MB -s "${rootfs}" | awk '{print $1}') + readonly rootfs_size_mb=$(du -B 1M -s "${rootfs}" | awk '{print $1}') readonly image="$(mktemp)" readonly mount_dir="$(mktemp -d)" readonly max_tries=20