Shrinking a thin-provisioned VMDK on a datastore with vmkfstools

Written by James McDonald

December 12, 2014

VMotion to another datastore didn’t work:

Just trying to shrink an already thin-provisioned Windows XP VM which is using only 10GB of a 127GB C: drive

I tried to run defrag, sdelete and then shutdown the VM and vmotion to another datastore with a target disk format of thin-provisioned  but this failed to reclaim the free space from the VM. By that I mean that the VMDK still used the same diskspace it originally did when it got to the target Datastore.

Instructions from the web

So next step was following instructions from

Problem when trying to run vmkfstools

After running a defrag on c: and sdelete -z c from inside the running VM and shutting it down to complete the vmkfstools -K [disk].vmdk I got

“Failed to open virtual disk ‘[disk].vmdk’: Failed to lock the file (16392)”

After investigating I found that Backup exec had taken a snapshot of the VM so that it could complete its backup. The fix was to wait till backup exec had completed its backup and removed the snapshot, and therefore the lock it had on the vmdk files.  I could then start the vmkfstools -K [disk].vmdk process

How I did the full process:

  1. Login the VM you want to shrink and defrag the disks
  2. Install sdelete and run sdelete -z C: (repeat for each drive)
  3. Shutdown the VM
  4. Enable SSH on the ESXi host that is hosting the VM and connect via PuTTY
  5. run vim-cmd vmsvc/getallvms and identify the VM ID and Name
  6. run vim-cmd vmsvc/get.datastores <ID>
  7. Using the id get the datastore url
  8. cd /vmfs/volumes/512d4228-3fbc76e4-93cb-d4ae52ba8566/<NAME>
  9. Run vmkfstools -K [disk].vmdk to reclaim the zeroed disks blocks.



Submit a Comment

Your email address will not be published.

You May Also Like…

MacOS USB Creator

Just toasted my Windows 10 Pro install with a Windows 11 upgrade. Think it will be unrecoverable (because of Bitlocker...