Shrink qcow2 with fstrim does not work

aPollO

Renowned Member
Mar 6, 2014
150
13
83
Cottbus, Germany
Hi Guys,

i tried to shrink the qcow2 image of my VMs. I have Linux Mint 19.2 guest with just 1 parition with ext4. See attached files for detailed configuration.
Run the fstrim command reports a trimmed filesystem but the size of the qcow2 file does not change.

1574786129527.png
1574786147200.png

Then i run the fstrim command:
1574786212715.png

Result is
-rw-r----- 1 root root 51G Nov 26 17:37 vm-210-disk-0.qcow2

What i'm doing wrong? "df" tells me that only 23GB of the 50GB partition is used.
 
Result is
-rw-r----- 1 root root 51G Nov 26 17:37 vm-210-disk-0.qcow2

Oh, did you use "ls" to the allocated size on disk? That won't work, as this "only" shows the metadatasize, which may not be the same as the allocated size, if the files has holes. E.g., if you would create a truncated massive file with: truncate -s 10TB foo.img you will also see 10TB file when using ls -lh, even if you do not have 10TB available.

You can use qemu-img info /path/to/disk.qcow2 or the "Blocks" value from a stat /path/.. if you want to use a more native tool.
 
  • Like
Reactions: aPollO
With qemi-img info i get reasonable values
Code:
virtual size: 50G (53687091200 bytes)
disk size: 21G


The stat command shows also ~50GB
Code:
Size: 53695545344     Blocks: 44206040   IO Block: 4096   regular file

I used ls for show the size cause i remembered i habe done this in the past. But maybe my memory is not correct.

My goal is to be able to overprovision the storage.
 

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!