Skip to content

Commit 6ec375d

Browse files
committed
Add check for lazy_refcounts
This will make sure if in future we do any other modification for qcow2 image generation/modification side then resulted image should always have `lazy_refcounts=true`.
1 parent 83556dc commit 6ec375d

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

createdisk.sh

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,19 @@ function create_qemu_image {
5555
${QEMU_IMG} create -o lazy_refcounts=on -f qcow2 $destDir/${CRC_VM_NAME}.qcow2 31G
5656
${VIRT_RESIZE} --expand /dev/sda3 $destDir/${VM_PREFIX}-base $destDir/${CRC_VM_NAME}.qcow2
5757

58-
# Make sure you have enough space in /tmp to run VIRT_SPARSIFY
58+
# TMPDIR must point at a directory with as much free space as the size of the image we want to sparsify
5959
# Read limitation section of `man virt-sparsify`.
6060
TMPDIR=$(pwd)/$destDir ${VIRT_SPARSIFY} -o lazy_refcounts=on $destDir/${CRC_VM_NAME}.qcow2 $destDir/${CRC_VM_NAME}_sparse.qcow2
6161
rm -f $destDir/${CRC_VM_NAME}.qcow2
6262
mv $destDir/${CRC_VM_NAME}_sparse.qcow2 $destDir/${CRC_VM_NAME}.qcow2
6363

64+
# Before using the created qcow2, check if it has lazy_refcounts set to true.
65+
lazy_refcounts=$(${QEMU_IMG} info ${destDir}/${CRC_VM_NAME}.qcow2 | grep -oP "lazy refcounts: true")
66+
if [ -z $lazy_refcounts ]; then
67+
echo "${CRC_VM_NAME}.qcow2 doesn't have lazy_refcounts enabled. This is going to cause disk image corruption when using with hyperkit"
68+
exit 1;
69+
fi
70+
6471
rm -fr $destDir/${VM_PREFIX}-master-0 $destDir/${VM_PREFIX}-base
6572
}
6673

0 commit comments

Comments
 (0)