From 0755f79785695ad693814812a9bb6f16332865bf Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 14 Nov 2019 15:47:20 +0000 Subject: [PATCH] create_disk: Make rootfs size small even for qemu/IaaS For RHCOS with encryption, we encrypt in early boot, and it's beneficial if the root filesystem size is small initially - distinct from the "default disk" size that applies in clouds (and libvirt). This helps RHCOS maintain its default 16G size for libvirt without requiring the installer and other tools to start resizing it. This also increases consistency across metal and virt - we now *always* run `coreos-growfs`. --- src/cmd-buildextend-metal | 38 +++++++++++++++++++++++++------------- src/create_disk.sh | 15 +++++++++++---- 2 files changed, 36 insertions(+), 17 deletions(-) diff --git a/src/cmd-buildextend-metal b/src/cmd-buildextend-metal index 828593139e..2f8a7b222a 100755 --- a/src/cmd-buildextend-metal +++ b/src/cmd-buildextend-metal @@ -140,19 +140,30 @@ 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" +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 + # Unset the root size, which will inherit from the image size + rootfs_size=0 else - size="$(python3 -c 'import sys, yaml; print(yaml.safe_load(sys.stdin)["size"])' < "$configdir/image.yaml")G" - ignition_platform_id="$image_type" + image_size="$(python3 -c 'import sys, yaml; print(yaml.safe_load(sys.stdin)["size"])' < "$configdir/image.yaml")G" + rootfs_size="${rootfs_size}M" fi kargs="$(python3 -c 'import sys, yaml; args = yaml.safe_load(sys.stdin).get("extra-kargs", []); print(" ".join(args))' < "$configdir/image.yaml")" @@ -167,7 +178,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 +202,7 @@ runvm "${target_drive[@]}" -- \ --ostree-remote "${ostree_remote}" \ --ostree-repo "${ostree_repo}" \ --save-var-subdirs "${save_var_subdirs}" \ + --rootfs-size "${rootfs_size}" \ "${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..db2ed47043 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,10 @@ set -x # Pin /boot and / to the partition number 1 and 4 respectivelly BOOTPN=1 ROOTPN=4 +# Make the size relative +if [ "${rootfs_size}" != "0" ]; then + rootfs_size="+${rootfs_size}" +fi case "$arch" in x86_64) sgdisk -Z $disk \ @@ -90,7 +97,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 +107,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 +115,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 +124,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 ;;