During testing with Talos Kubernetes deployments on Libvirt, I encountered an issue where created virtual machines used fully provisioned disks, which consumed the complete configured disk size on the host system.
Since most of my testing happens on my notebook with locally provisioned virtual machines, I prefer to use thin-provisioned disks to conserve disk space.
The easiest solution is to convert the qcow2 images using virt-sparsify, which is part of Libguesttools. A good reference is the Red Hat Documentation: 21.14. virt-sparsify: Reclaiming Empty Disk Space.
virt-sparsify <disk-image-to-convert> <name-of-new-image>
Warning
Power down the virtual machine before converting the disk images!
Example #
# Run as root to convert system disk images
sudo su -
cd /var/lib/libvirt/images
virt-sparsify cnx8-rb-master.qcow2 cnx8-rb-master_thin.qcow2
mv cnx8-rb-master.qcow2 cnx8-rb-master_full.qcow2
mv cnx8-rb-master_thin.qcow2 cnx8-rb-master.qcow2Test the virtual machine before deleting the old disk!
Space Differences #
ls -alh cnx8-rb-master*
-rw-r--r--. 1 root root 41G Dec 17 16:06 cnx8-rb-master_full.qcow2
-rw-r--r--. 1 root root 2.3G Dec 17 16:08 cnx8-rb-master_thin.qcow2Delete Full Provisioned Disk #
rm cnx8-rb-master_full.qcow2