diff --git a/src/cmd-buildextend-metal b/src/cmd-buildextend-metal index 828593139e..2cb52ff7bd 100755 --- a/src/cmd-buildextend-metal +++ b/src/cmd-buildextend-metal @@ -140,19 +140,26 @@ fi img=${name}-${build}-${image_type}.${basearch}.${image_format} path=${PWD}/${img} -# For bare metal images, we estimate the disk size. For qemu, we get it from -# image.yaml. -if [[ $image_type == metal || $image_type == dasd ]]; then - echo "Estimating disk size..." - /usr/lib/coreos-assembler/estimate-commit-disk-size --repo "$ostree_repo" "$ref" --add-percent 20 > "$PWD/tmp/ostree-size.json" - size="$(jq '."estimate-mb".final' "$PWD/tmp/ostree-size.json")" - # extra size is the non-ostree partitions, see create_disk.sh - size="$(( size + 513 ))M" - echo "Disk size estimated to $size" - ignition_platform_id="metal" -else - size="$(python3 -c 'import sys, yaml; print(yaml.safe_load(sys.stdin)["size"])' < "$configdir/image.yaml")G" - ignition_platform_id="$image_type" +ignition_platform_id="${image_type}" +# dasd is a different disk format, but it's still metal. Just like +# if in the future we introduce a 4k sector size x86_64 image type (metal-4k). +if [ "${image_type}" = dasd ]; then + ignition_platform_id=metal +fi + +echo "Estimating disk size..." +# The additional 35% here is obviously a hack, but we can't easily completely fill the filesystem, +# and doing so has apparently negative performance implications. +/usr/lib/coreos-assembler/estimate-commit-disk-size --repo "$ostree_repo" "$ref" --add-percent 35 > "$PWD/tmp/ostree-size.json" +rootfs_size="$(jq '."estimate-mb".final' "$PWD/tmp/ostree-size.json")" +# extra size is the non-ostree partitions, see create_disk.sh +image_size="$(( rootfs_size + 513 ))M" +echo "Disk size estimated to ${image_size}" + +# For bare metal images, we use the estimated image size. For IaaS/virt, we get it from +# image.yaml because we want a "default" disk size that has some free space. +if [ "${image_type}" != metal ]; then + image_size="$(python3 -c 'import sys, yaml; print(yaml.safe_load(sys.stdin)["size"])' < "$configdir/image.yaml")G" fi kargs="$(python3 -c 'import sys, yaml; args = yaml.safe_load(sys.stdin).get("extra-kargs", []); print(" ".join(args))' < "$configdir/image.yaml")" @@ -167,7 +174,7 @@ ostree_remote="$(python3 -c 'import sys, yaml; print(yaml.safe_load(sys.stdin).g save_var_subdirs="$(python3 -c 'import sys, yaml; print(yaml.safe_load(sys.stdin).get("save-var-subdirs-for-selabel-workaround", "NONE"))' < "$configdir/image.yaml")" luks_flag="$(python3 -c 'import sys, yaml; lf=yaml.safe_load(sys.stdin).get("luks_rootfs", ""); print("--luks-rootfs" if lf.lower() in ("yes", "true") else "")' < "$configdir/image.yaml")" -qemu-img create -f ${image_format} "${path}.tmp" "$size" +qemu-img create -f ${image_format} "${path}.tmp" "${image_size}" # We support deploying a commit directly instead of a ref ref_arg=${ref} if [ -n "${ref_is_temp}" ]; then @@ -191,6 +198,7 @@ runvm "${target_drive[@]}" -- \ --ostree-remote "${ostree_remote}" \ --ostree-repo "${ostree_repo}" \ --save-var-subdirs "${save_var_subdirs}" \ + --rootfs-size "${rootfs_size}M" \ "${luks_flag}" mv "${path}.tmp" "$path" echo "{}" > tmp/vm-iso-checksum.json diff --git a/src/create_disk.sh b/src/create_disk.sh index 31e0d8d540..7967490285 100755 --- a/src/create_disk.sh +++ b/src/create_disk.sh @@ -27,6 +27,7 @@ Options: --ostree-remote: the ostree remote --ostree-repo: location of the ostree repo --save-var-subdirs: "yes" to workaround selabel issue for RHCOS + --rootfs-size: Create the root filesystem with specified size --luks-rootfs: place rootfs in a LUKS container You probably don't want to run this script by hand. This script is @@ -34,6 +35,7 @@ run as part of 'coreos-assembler build'. EOC } +rootfs_size="0" luks_rootfs="" extrakargs="" @@ -52,6 +54,7 @@ do --ostree-remote) remote_name="${1}"; shift;; --ostree-repo) ostree="${1}"; shift;; --save-var-subdirs) save_var_subdirs="${1}"; shift;; + --rootfs-size) rootfs_size="${1}"; shift;; --luks-rootfs) luks_rootfs=1;; *) echo "${flag} is not understood."; usage; exit 10;; --) break; @@ -83,6 +86,8 @@ set -x # Pin /boot and / to the partition number 1 and 4 respectivelly BOOTPN=1 ROOTPN=4 +# Make the size relative +rootfs_size="+${rootfs_size}" case "$arch" in x86_64) sgdisk -Z $disk \ @@ -90,7 +95,7 @@ case "$arch" in -n ${BOOTPN}:0:+384M -c ${BOOTPN}:boot \ -n 2:0:+127M -c 2:EFI-SYSTEM -t 2:C12A7328-F81F-11D2-BA4B-00A0C93EC93B \ -n 3:0:+1M -c 3:BIOS-BOOT -t 3:21686148-6449-6E6F-744E-656564454649 \ - -n ${ROOTPN}:0:0 -c ${ROOTPN}:root -t ${ROOTPN}:0FC63DAF-8483-4772-8E79-3D69D8477DE4 + -n ${ROOTPN}:0:${rootfs_size} -c ${ROOTPN}:root -t ${ROOTPN}:0FC63DAF-8483-4772-8E79-3D69D8477DE4 sgdisk -p "$disk" EFIPN=2 BIOSPN=3 @@ -100,7 +105,7 @@ case "$arch" in -U 00000000-0000-4000-a000-000000000001 \ -n ${BOOTPN}:0:+384M -c ${BOOTPN}:boot \ -n 2:0:+127M -c 2:EFI-SYSTEM -t 2:C12A7328-F81F-11D2-BA4B-00A0C93EC93B \ - -n ${ROOTPN}:0:0 -c ${ROOTPN}:root -t ${ROOTPN}:0FC63DAF-8483-4772-8E79-3D69D8477DE4 + -n ${ROOTPN}:0:${rootfs_size} -c ${ROOTPN}:root -t ${ROOTPN}:0FC63DAF-8483-4772-8E79-3D69D8477DE4 sgdisk -p "$disk" EFIPN=2 ;; @@ -108,7 +113,7 @@ case "$arch" in sgdisk -Z $disk \ -U 00000000-0000-4000-a000-000000000001 \ -n ${BOOTPN}:0:+384M -c ${BOOTPN}:boot \ - -n ${ROOTPN}:0:0 -c ${ROOTPN}:root -t ${ROOTPN}:0FC63DAF-8483-4772-8E79-3D69D8477DE4 + -n ${ROOTPN}:0:${rootfs_size} -c ${ROOTPN}:root -t ${ROOTPN}:0FC63DAF-8483-4772-8E79-3D69D8477DE4 sgdisk -p "$disk" ;; ppc64le) @@ -117,7 +122,7 @@ case "$arch" in -U 00000000-0000-4000-a000-000000000001 \ -n 2:0:+4M -c 2:PowerPC-PReP-boot -t 2:9E1A2D38-C612-4316-AA26-8B49521E5A8B \ -n ${BOOTPN}:0:+384M -c ${BOOTPN}:boot \ - -n ${ROOTPN}:0:0 -c ${ROOTPN}:root -t ${ROOTPN}:0FC63DAF-8483-4772-8E79-3D69D8477DE4 + -n ${ROOTPN}:0:${rootfs_size} -c ${ROOTPN}:root -t ${ROOTPN}:0FC63DAF-8483-4772-8E79-3D69D8477DE4 sgdisk -p "$disk" PREPPN=2 ;;