Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
Which hypervisor? – Massimo Jul 27 '10 at 20:38
vmdks are with VMware – warren Jul 27 '10 at 20:55
up vote 3 down vote accepted

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.

share|improve this answer

For VHD files only, on Hyper-V, open the Hyper-V Manager, select Edit Disk from the actions pane, select the VHD file, and the Compact option. Cook until golden brown.

share|improve this answer
While your answer is correct, I believe it only applies to file systems that Windows supports. The OP asked about CentOS, Slackware and Ubuntu. I don't think Hyper-V can mount the file systems which tend to be in use with those OSes, which is part of compaction. – Jake Oshins Jul 27 '10 at 22:09
Actually, let me add to that. Hyper-V can still do some compaction, if the virtual disk contains zeros in allocated blocks. You can help this process along with those Linuxes if you can tell them to defragment and zero unused regions of the disk. Otherwise, you'll probably get little benefit from compaction. What you really don't want to do is to defragment from within the guest OS if they won't zero the blocks. This will just cause your virtual disk to balloon out with little hope of reclaiming anything. – Jake Oshins Jul 27 '10 at 22:24
Correct, the blocks have to be zeroed or the file system has to be NTFSv5 for Hyper-V (or Windows 2008R2/7) to compact the drive. I believe there's a utility available to do so, but I can't recall the name. – Chris S Jul 27 '10 at 23:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.