Is it possible to re-shrink the .qcow2 image files?

this is actually much simpler now in KVM. zerofree runs and the other commands are no longer required. it basically just requires one to set the “discard” flag on a mount option for the disk in question and then set “discard mode” to “unmap” in virt-manager. for example:

  1. in /etc/fstab, set the following for root:
    “/dev/disk/by-uuid/XXXXXX-blah-blah-YourdiskUUID / auto defaults,errors=remount-ro,discard 0 1”

  2. in the “virt-manager” program, click on the virtual machine in question, open the virtual machine in question, click on the lightbulb icon to get to its settings, click on the storage disk in question and go to the “advanced options.” then, next to “discard mode,” choose “unmap.”

the disk will no longer balloon. unused diskspace will get released naturally, or can be forced with the “sudo fstrim -av” command.

1 Like