I’m currently running some VMs on my home server with libvirt + Kimchi.
The VMs are stored in QCOW2 files and I noticed that over time they tend do expand beyond the size specified for the VM.
I did a quick Googling [1, 2] and I found that you can setup the VMs using the VirtIO-SCSI controller and run fstrim on the guest periodically to reclaim the unused space. But, apparently there are some limitations (e.g. it doesn’t seem to work if the VM has snapshots).
I also noticed that once fstrim has ran ls -l doesn’t show the reduced filesize on the host, but if you look at du or qemu-img info the filesize has been reduced. Not sure why.
How are you guys dealing with this issue when setting up VMs?
I found it also to be dependant on the fs you use on the guest and the way that fs utilizes free space. normal ext4 for instance first writes to former unused blocks, which makes sparse images grow steadily, even if you delete files on the guest. fstrim isn’t always correctly supported on top of that
xfs on the other hand does first overwrite former used blocks, so won’t neccessarily grow the sparse as fast as ext4 might do. so using that might help with the need to use trim or rewrite the sparse images, but ofc xfs does have its own caveats.
Depending on the guests disk activity, a dozen VMs on a host and you’ll be running out of space at some point. And you can’t count on clients running trim on their environments. Unless that is being built-in in the OS images offered.
For Proxmox, I have FSTrim installed on all VMs. They are setup with VirtIO SCSI for the SCSI controller under options. Under the hardware section I have the hard drive as a SCSI device with discard enabled. Make sure to restart the VMs, and then run FSTrim -a -v. Also, some VMs need the good old hole punching method.