How to shrink VM disk

Apr 12, 2018
31
3
13
38
Hi,
I have a proxmox with 3 containers and 2 virtual machines, all on a ZFS storage. There is one thing that is automatic with containers and that I would like to do with VMs:

I create a virtual machine with a 500 GB disk. On the ZFS, I enabled the "Thin Provisioning" function, which means that at the beginning, the disk has a size almost zero and grows as and when as I put things on it. Currently, the actual size is around 400 GB.

Then, I delete the files from the virtual machine (from the perspective of the virtual machine, there is only 100 GB of used) and I wish the disk is reduced to save space.

Possible? How?
 
You should use virtio-scsi driver with discard option and inside the VM use the TRIM function (fstrim from linux, during the maintenance time in windows)
 
First you should install virtio-scsi drivers, adding a new virtio-scsi virtual disk and installing the driver.
After that you can remove all the virtual disks and re-add them as virtio-scsi with the discard option enabled.
From Windows 7 / Windows server 2008R1 up to Windows 10/Windows Server 2016, TRIM is enabled by default on SSD and thin provisoned disks
 
From the web interface, in the Hardware tab of the VM, you have the option to DETACH a virtual disk. After you click on detach, the disk is kept as unused, just double click the unused disk and add it as virtio-scsi with discard enabled
 

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!