How to the “actual” size of VHD/VMDK files be reduced after deleting unwanted files

storagevirtual-diskvirtualization

Somewhat akin to this question I asked on superuser, and this one for Hyper-V, after deleting files from a VM, how can the virtual disks be resized back downwards?

For example, perhaps the VM has 40GB of free space. The virtual disk was setup to allocate on-demand, so it's actual size on the SAN is, say, 3.4 GB.

Then all of the installation ISOs for CentOS, Slackware, and Ubuntu are downloaded to create a local mirror.

After some period of time, unneeded ISOs are deleted, bringing the VM's free space back to 23GB.

How can the virtual disk that was expanded as needed be reshrunk to a minimal size?

Is that even a worth-while consideration?

Best Answer

If you want to shrink a thin provisioned drive you probably need to start by using a tool like zerofree or sdelete to zero out all the empty space. Then use a tool appropriate to your hypervisor to clone recreate the VM from the old disk file.

With Vmware products you can use VMware Converter to create a new VM from the old and if you thin-provision the and adjust the storage settings the new VM should only use the amount of space used by the files on the virtual disk.

As for worthwhile, that is kind of up to you. It would depend a lot on how much free storage you have. How much space has been wasted, if you can afford some downtime to create a smaller disk, and if that time is more valuable then the cost of additional storage.