From 71f27e157bd34c4182f5fa670d12f308e9bb1830 Mon Sep 17 00:00:00 2001 From: Praveen Kumar Date: Thu, 14 Nov 2019 10:58:18 +0530 Subject: [PATCH 1/2] Use root labeled partition to resize the disk image In 4.2 the root partition mounted on `/dev/sda3` but for 4.3 it is mounted on `/dev/sda4` so to work properly with both the version, it is good to detect first and then use for `virt-resize`. - 4.2 image ``` $ virt-filesystems -a crc.qcow2 -l Name Type VFS Label Size Parent /dev/sda2 filesystem ext4 boot 1073741824 - /dev/sda3 filesystem xfs root 32208846848 - ``` - 4.3 image ``` $ virt-filesystems -a crc.qcow2 -l Name Type VFS Label Size Parent /dev/sda1 filesystem ext4 boot 402653184 - /dev/sda2 filesystem vfat EFI-SYSTEM 133169152 - /dev/sda4 filesystem xfs root 16641932800 - ``` --- createdisk.sh | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/createdisk.sh b/createdisk.sh index 6ca601ed..7a7406d9 100755 --- a/createdisk.sh +++ b/createdisk.sh @@ -50,9 +50,12 @@ function create_qemu_image { ${QEMU_IMG} rebase -b ${VM_PREFIX}-base $destDir/${VM_PREFIX}-master-0 ${QEMU_IMG} commit $destDir/${VM_PREFIX}-master-0 + # Check which partition is labeled as `root` + partition=$(${VIRT_FILESYSTEMS} -a $destDir/${VM_PREFIX}-base -l | grep root | cut -f1 -d' ') + # Resize the image from the default 1+15GB to 1+30GB ${QEMU_IMG} create -o lazy_refcounts=on -f qcow2 $destDir/${CRC_VM_NAME}.qcow2 31G - ${VIRT_RESIZE} --expand /dev/sda3 $destDir/${VM_PREFIX}-base $destDir/${CRC_VM_NAME}.qcow2 + ${VIRT_RESIZE} --expand $partition $destDir/${VM_PREFIX}-base $destDir/${CRC_VM_NAME}.qcow2 if [ $? -ne 0 ]; then echo "${VIRT_RESIZE} call failed, disk image was not properly resized, aborting" exit 1 @@ -192,6 +195,7 @@ JQ=${JQ:-jq} VIRT_RESIZE=${VIRT_RESIZE:-virt-resize} QEMU_IMG=${QEMU_IMG:-qemu-img} VIRT_SPARSIFY=${VIRT_SPARSIFY:-virt-sparsify} +VIRT_FILESYSTEMS=${VIRT_FILESYSTEMS:-virt-filesystems} if [[ $# -ne 1 ]]; then echo "You need to provide the running cluster directory to copy kubeconfig" @@ -206,6 +210,10 @@ if ! which ${VIRT_RESIZE}; then sudo yum -y install /usr/bin/virt-resize libguestfs-xfs fi +if ! which ${VIRT_FILESYSTEMS}; then + sudo yum -y install /usr/bin/virt-filesystems +fi + # The CoreOS image uses an XFS filesystem # Beware than if you are running on an el7 system, you won't be able # to resize the crc VM XFS filesystem as it was created on el8 From b178df374c7fdfa8315ced1ea292fadea99e93c4 Mon Sep 17 00:00:00 2001 From: Praveen Kumar Date: Wed, 13 Nov 2019 12:19:06 +0530 Subject: [PATCH 2/2] Issue #129 Workaround for virt-sparsify to work with immutable partition With OpenShift-4.3 the rh-coreos image failed during sparsify because of the immutable attribute set for /dev/sda4 partition. Need to use guestfish to remove it and run the virt-sparsify and then apply back. - https://bugzilla.redhat.com/show_bug.cgi?id=1771257 --- createdisk.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/createdisk.sh b/createdisk.sh index 7a7406d9..b57b3be9 100755 --- a/createdisk.sh +++ b/createdisk.sh @@ -61,6 +61,9 @@ function create_qemu_image { exit 1 fi + # Remove immutable attribute for OpenShift 4.3+ + guestfish -a $destDir/${CRC_VM_NAME}.qcow2 -m /dev/sda4 set-e2attrs / i clear:true + # TMPDIR must point at a directory with as much free space as the size of the image we want to sparsify # Read limitation section of `man virt-sparsify`. TMPDIR=$(pwd)/$destDir ${VIRT_SPARSIFY} -o lazy_refcounts=on $destDir/${CRC_VM_NAME}.qcow2 $destDir/${CRC_VM_NAME}_sparse.qcow2 @@ -68,6 +71,9 @@ function create_qemu_image { mv $destDir/${CRC_VM_NAME}_sparse.qcow2 $destDir/${CRC_VM_NAME}.qcow2 rm -fr $destDir/.guestfs-* + # Set immutable attribute back for /dev/sda4 + guestfish -a $destDir/${CRC_VM_NAME}.qcow2 -m /dev/sda4 set-e2attrs / i + # Before using the created qcow2, check if it has lazy_refcounts set to true. ${QEMU_IMG} info ${destDir}/${CRC_VM_NAME}.qcow2 | grep "lazy refcounts: true" 2>&1 >/dev/null if [ $? -ne 0 ]; then