Skip to content

Commit

Permalink
create_disk: Make rootfs size small even for qemu/IaaS
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
cgwalters committed Nov 18, 2019
1 parent 225b113 commit e441a6a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 18 deletions.
36 changes: 22 additions & 14 deletions src/cmd-buildextend-metal
Original file line number Diff line number Diff line change
Expand Up @@ -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")"
Expand All @@ -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
Expand All @@ -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
Expand Down
13 changes: 9 additions & 4 deletions src/create_disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ 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
run as part of 'coreos-assembler build'.
EOC
}

rootfs_size="0"
luks_rootfs=""
extrakargs=""

Expand All @@ -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;
Expand Down Expand Up @@ -83,14 +86,16 @@ 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 \
-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 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
Expand All @@ -100,15 +105,15 @@ 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
;;
s390x)
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)
Expand All @@ -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
;;
Expand Down

0 comments on commit e441a6a

Please sign in to comment.