Following method only works for virtual machines (VM) that are satisfying these pre-requirements:
- Thin-provisioned backing storage (qcow2 disk, thin-lvm, zfs, …)
- Virtio-SCSI controller configured on guest.
- Guest scsi disks with the discard option enabled 
Note: While changing provisioning types and Virtio-SCSI driver are not easy with existing virtual machines, but changing VM scsi disk’s discard options is simple, that means, if we appear to have an existing VM that is using thin-provisioned backing storage and Virtio-SCSI but “discard” options is not enabled/checked, we can simply find that VM and check that option, then we are good to follow the reset of this guide.
When we are using qcow2 sparse virtual disks, we can reclaim free disk spaces which are not using by the virtual machine. How to trigger the VM/guest operating system to reclaim it for us though?
1 Login to Proxmox VE web gui
2 Find the VM we want to reclaim the unused disk space for and click on it
3 Click on Hardware
4 Double click on the virtual hard’s virtual hard drive we want to reclaim unused space for
5 Make sure the “Discard” is checked
6 Start the VM
Once the VM is fully booted
6a For Linux/Debian/Ubuntu/Kali Linux/CentOS/RHEL/Fedora etc.
6a.1 We use following command to reclaim the unused disk space from a terminal
sudo fstrim -av
Once it’s done, we should be able to see the reclaimed disk space from Proxmox VE host (Only if there is unused space, if there is no unused space, we will not see any changes from Proxmox VE host’s disk space)
6a.2 We can also enable the automatic fstrim from the VM, so we do not need to do it manually everytime. Use following command to enable this feature
sudo systemctl enable fstrim.timer
6b For Windows
Usually the trim is enabled by default on Windows (Windows 7/2008R2 and up), we should not need to modify anything.
We can check if TRIM is enabled or not by using following command
fsutil behavior query DisableDeleteNotify
The output should be 0, otherwise, we can set it manually
fsutil behavior set DisableDeleteNotify 0
We can also trigger it manually, here is how.
First, we need to shutdown the Windows VM.
Then from the Proxmox VE web gui, find the Windows VM, Navigate to “Hardware”, double click on the virtual hard drive that we want to reclaim unused space from, make sure the “Discard” and “SSD emulation” are both checked, now start the Windows VM
When the Windows booted, we type “defrag” in start menu to search for “Defragment and Optimize Drives” program.
Click on it to launch it, then select the drive which we want to claim unused space from, click on “Optimize” button.
We now have manually reclaimed unused space from Windows VM
 “Shrink Qcow2 Disk Files – Proxmox VE”, Pve.proxmox.com, 2019. [Online]. Available: https://pve.proxmox.com/wiki/Shrink_Qcow2_Disk_Files