Skip to content

Commit

Permalink
Add check for lazy_refcounts
Browse files Browse the repository at this point in the history
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`.
  • Loading branch information
praveenkumar committed Aug 31, 2019
1 parent 83556dc commit 6ec375d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion createdisk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,19 @@ function create_qemu_image {
${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

# Make sure you have enough space in /tmp to run VIRT_SPARSIFY
# 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
rm -f $destDir/${CRC_VM_NAME}.qcow2
mv $destDir/${CRC_VM_NAME}_sparse.qcow2 $destDir/${CRC_VM_NAME}.qcow2

# Before using the created qcow2, check if it has lazy_refcounts set to true.
lazy_refcounts=$(${QEMU_IMG} info ${destDir}/${CRC_VM_NAME}.qcow2 | grep -oP "lazy refcounts: true")
if [ -z $lazy_refcounts ]; then
echo "${CRC_VM_NAME}.qcow2 doesn't have lazy_refcounts enabled. This is going to cause disk image corruption when using with hyperkit"
exit 1;
fi

rm -fr $destDir/${VM_PREFIX}-master-0 $destDir/${VM_PREFIX}-base
}

Expand Down

0 comments on commit 6ec375d

Please sign in to comment.