VM (Windows 2022) - shrink qcow2

virmix

Member
Sep 4, 2020
36
1
13
https://pve.proxmox.com/wiki/Shrink_Qcow2_Disk_Files

I try all steps but not work:

Windows Guest Preparation​

I shrink partition inside Windows. The HD SIZE : 600GB , and I shrink 450GB. No I have a fee space.

1639399549821.png

Then I use Windows Defrag and then and then Sdelete

Proxmox shell Preparation​

Copy File : cp vm-101-disk-1.qcow2 new.qcow2
Convert : qemu-img convert -p -O qcow2 new.qcow2 shrink.qcow2

No error.

new.qcow2 and shrink.qcow2 have the same size. I dont know what can I do.
 
Could you post the config file for the VM? (cat /etc/pve/qemu-server/<vmid>)
 
Could you post the config file for the VM? (cat /etc/pve/qemu-server/<vmid>)



Code:
agent: 1
bios: ovmf
boot: order=virtio0;net0
cores: 6
efidisk0: local:101/vm-101-disk-0.qcow2,efitype=4m,pre-enrolled-keys=1,size=528K
machine: pc-q35-6.1
memory: 10240
meta: creation-qemu=6.1.0,ctime=1637597607
name: Win2022
net0: virtio=1E:44:C3:CE:B1:02,bridge=vmbr0,firewall=1
numa: 0
onboot: 1
ostype: win11
protection: 1
scsihw: virtio-scsi-pci
smbios1: uuid=b3b12d4f-ea4c-42ac-a168-5879775b2064
sockets: 1
vga: virtio
virtio0: local:101/vm-101-disk-1.qcow2,cache=writethrough,discard=on,size=700G
virtio1: local:101/vm-101-disk-2.qcow2,cache=writethrough,discard=on,size=600G
vmgenid: 5a93beac-623a-47be-a32a-b7c4c176ec1
 
Last edited:
new.qcow2 and shrink.qcow2 have the same size. I dont know what can I do.

How are you checking the size of the qcow2 files? ls will report the same size for both, but du -sh should show some differencies.

If you run defrag/sdelete on your C: drive after shrinking, the free space won't be "sdelete'ed", so it will keep it's original data, thus using space in the qcow file. Create a new partition in that space and run sdelete on it to zero out all of it, then remove the unit and wait some time so the TRIM/discard gets actually applied by the OS to the virtual disk.
 
How are you checking the size of the qcow2 files? ls will report the same size for both, but du -sh should show some differencies.

If you run defrag/sdelete on your C: drive after shrinking, the free space won't be "sdelete'ed", so it will keep it's original data, thus using space in the qcow file. Create a new partition in that space and run sdelete on it to zero out all of it, then remove the unit and wait some time so the TRIM/discard gets actually applied by the OS to the virtual disk.

Yes, I move all particion at the start of vm-disc. Then I run defrag, and finish I resetart and run sdelete. Then I convert qcow2 , but size of file is the same

1639416911942.png

1639417775058.png


541.85 GB free
1639399549821.png
 
Last edited:
So you are running sdelete on your C: instead of the empty space that was left after the shrink procedure.

Code:
Create a new partition in that space and run sdelete on it to zero out all of it, then remove the unit and wait some time so the TRIM/discard gets actually applied by the OS to the virtual disk
 
So you are running sdelete on your C: instead of the empty space that was left after the shrink procedure.

Code:
Create a new partition in that space and run sdelete on it to zero out all of it, then remove the unit and wait some time so the TRIM/discard gets actually applied by the OS to the virtual disk

OS inside VM cannot do that. The TRIM only frees the VM space, but does not reduce the file qcow2 size

Well I do it and the result is the same.
 
Last edited:

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!