Reclaiming space from thin provisioned disks in VMware ESXi

This is the procedure that has worked for me. There are various methods dating as far back as 2011 across the internet, but this step-by-step works in my environment for Windows and Linux virtual machines.

Step 1 - Prepare the Guest Operating Systems

Windows

Linux

  • For each volume you’ll want to run the following
    • dd if=/dev/zero of=/volume/zero.fill bs=1024k
  • After that completes, remove the zero.fill file from each volume.
    • rm /volume/zero.fill
  • To to Step 2

Step 2 - Punch some Holes

  • Shut down the virtual machine and power it off in vCenter or on the ESXi host
  • Log into the ESXi host via SSH
  • Navigate to the volume where the VM is stored
    • cd /vmfs/volumes/datastore/VirtualMachine
  • Punch the holes
    • vmkfstools -K VirtualMachine.vmdk
  • When completed, back in vCenter or the ESXi host web management, remove the VM from inventory (do not delete from disk). Use the following commands as root on the ESXi host also.
    • Unregister VM (More Info)
      • vim-cmd vmsvc/unregistervm _vmid_
        • You can get the vmid using vim-cmd vmsvc/getallvms
  • Add the VM back into inventory (go to the datastore and browse for where it is at; select the .vmx and click Register VM). Use the following commands as root on the ESXi host also.
    • Register VM (More Info)
      • vim-cmd solo/registervm /vmfs/volumes/ _datastore_name_ / _VM_directory_ / _VM_name.vmx_
#SysInternals #VMware