Freeing Up Unused Space In A Linux VM That Doesn't Support TRIM

Tony C

Member
May 28, 2020
22
2
8
Hi all,

I'm usng LVM-Thin storage for my VMs, one of which is a very old legacy Linux VM. So old that the kernel doesn't support TRIM. The file system is EXT2. Is it possible to somehow run fstrim from the PVE host on the lvm-thin volume and have the space reclaimed in the lvm-thin pool? The VM would be shutdown whilst I do this of course.

You can do this for containers with `pct fstrim` is there an equivalent for KVM/QEMU VMs? A quick grep of the Perl files seems to suggest the only thing supported is submitting an fstrim request via the guest agent.

Many thanks in advance,

Tony.
 
Subscribing for curiosity.
Thinking outside the box, if this VM is so ancient, can you move it to spinning disk and thus workaround/bypass the trim issue?
 
Subscribing for curiosity.
Thinking outside the box, if this VM is so ancient, can you move it to spinning disk and thus workaround/bypass the trim issue?
I simply want to shrink the disk down to free up unused space, returning it to the LVM thin pool. The VM itself runs fine, but at the moment the only way to reclaim the space would be to either do a native back up of the disk, recreate the disk and restore from backup. Or mount the disk in another VM which does support fstrim and then run it on that filesystem. Both are doable but a bit clunky. If it can be done for a CT then you should be able to do it for a VM. I suspect they didn't bother implementing the feature as it's a very rare use case (TRIM support was added ages ago), whereas for a CT it's pretty common place.
 
Last edited:
The file system is EXT2. Is it possible to somehow run fstrim from the PVE host on the lvm-thin volume and have the space reclaimed in the lvm-thin pool?

Very good question and good idea. It'll work from the host.

You may need to load the partition table with kpartx so that you have the actual partition, mount it and run fstrim. I just tried with an ext2 filesystem and I was able to trim it from the host. Another necessity to get the lowest possible filesystemsize is to run a defrag operation. LVM thin uses 2 MB allocation units, so things should be packed on the filesystem and not scattered over the whole disk.
 
Very good question and good idea. It'll work from the host.

You may need to load the partition table with kpartx so that you have the actual partition, mount it and run fstrim. I just tried with an ext2 filesystem and I was able to trim it from the host. Another necessity to get the lowest possible filesystemsize is to run a defrag operation. LVM thin uses 2 MB allocation units, so things should be packed on the filesystem and not scattered over the whole disk.
Thank you very much for your reply :). Interesting. So the reclaiming of disk space is a function solely within LVM and not PVE (beyond passing the TRIM requests through to LVM). For some reason I got it into my head that PVE was passing explicit `return this block to the free pool' requests to LVM. Interesting point about the defragging first.

Many thanks once again. Tony.
 

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!