#!/bin/bash # sparse and compress guest image # use ramdisk to spare ssd writes (note the amount of RAM needed) date +%F_%T \ && \ cd /var/lib/libvirt/images/ \ && \ mount -t tmpfs -o size=32g tmpfs /mnt \ && \ mkdir /mnt/tmp \ && \ TMPDIR=/mnt/tmp virt-sparsify arch.qcow2 /mnt/tmp.qcow2 \ && \ sync \ && \ qemu-img convert -O qcow2 -c /mnt/tmp.qcow2 arch.qcow2 \ && \ sync \ && \ ls -lh \ && \ umount /mnt \ && \ date +%F_%T