shrinking qcow2 file does not free up space on host

krato

New Member
Sep 18, 2024
4
0
1
So I shrinked my zfs partition inside qcow2 VM and then shrinked actual qcow2 file with qemu-img.

The qcow2 file went from 32 GB to 10GB, but the free space on host ZFS partition is exactly the same

I have not made any mistake, this ZFS partition is mounted in /var/lib/vz and the qcow2 file for my VM is inside this folder: /var/lib/vz/images/103

After running qemu-img the old qcow2 was of course deleted

I DO NOT have zfs compression enabled, however it feels to me like the empty space inside qcow2 file somehow did not take any space on host ZFS, how is that possible? I see this behaviour for the first time

zfs get compression data
NAME PROPERTY VALUE SOURCE
data compression off local
 
I read the thread that you quoted but I am not sure which part applies to me

is it "by default Proxmox VE uses qemu-img with preallocation=metadata to create images, which only allocates the metadata up front." ?

which would mean that qcow2 file is showing size as 32GB for example but on the filesystem it takes lets say only 10GB?

This does not seem to be the case here, the example file that I am checking is 33GB no matter how I check it

root@proxmox2:/var/lib/vz/images/106# du -h vm-106-disk-0.qcow2
33G vm-106-disk-0.qcow2

root@proxmox2:/var/lib/vz/images/106# stat vm-106-disk-0.qcow2
File: vm-106-disk-0.qcow2
Size: 34365243392 Blocks: 67351057 IO Block: 131072 regular file
Device: 0,41 Inode: 257 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2024-09-18 09:12:00.403633128 +0000
Modify: 2024-09-18 09:16:32.214655158 +0000
Change: 2024-09-18 09:16:32.214655158 +0000
Birth: 2024-09-06 19:38:24.974530386 +0000


After shrinking other similar file is showing 10GB filesystem size but the free space has not increased by ~20GB
 
Last edited:
The qcow2 file you show appears to be 32GB, but that doesn’t mean it actually uses 32G, qcow2 is sparse which means zero-filled blocks shouldn’t actually take up any space but if you use the space it doesn’t just shrink on itself.

I’m not sure how you measure free space, but depending on how accounting works on the file system, you likewise get a state where you “used” 32G but I believe in certain cases ZFS will appear as if your partition total size has grown (original size + free space.)

So depending on your current state, if you never used the space, your free space won’t change because it isn’t actually being used if you ever used 10G even if you shrink partitions etc, you’re still just using ~10G However if you did use the space, you can’t shrink a qcow2 file direct, you’d have to first call trim, which will reduce the space used, then convert the entire file to a new file if you want to make it actually smaller.

Did you follow these instructions? https://pve.proxmox.com/wiki/Shrink_Qcow2_Disk_Files
 
Last edited:
Your response is exactly what I suspected. However I cannot find any information in this thread, or in google, how to check the actual space the UNSHRINKED! qcow2 file is occupying on the filesystem. stat and du both show 33GB as showed above for the file that was not compressed

Yes I did follow exactly these instructions to shrink the qcow2 file and I shrinked another qcow2 file from 32GB to 14 GB, here is what du and stats shows

du -h vm-103-disk-0.qcow2
14G vm-103-disk-0.qcow2

stat vm-103-disk-0.qcow2
File: vm-103-disk-0.qcow2
Size: 14545584128 Blocks: 28428497 IO Block: 131072 regular file
Device: 0,41 Inode: 1160 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2024-09-18 09:16:02.595979661 +0000
Modify: 2024-09-18 09:53:04.572651457 +0000
Change: 2024-09-18 09:53:04.572651457 +0000
Birth: 2024-09-18 00:43:45.008742781 +0000

I saved around 18GB on this file(theoretically), but in fact the free space on filesystem has not changed
 

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!