Safely Shrinking VMware Server / Workstation .vmdk Files

If like me, you originally implemented some of your VMs in VMware Server (or Workstation) as thick provisioned, and have subsequently changed your mind, the process for converting them back to thin is very simple. In my case, the driver was the purchase of a couple of new SSDs, which obviously have a lot less space than my old 7200RPM SATA disks, but the performance is  significantly better.

Before shrinking your VM, be sure to zero out all of the unused space (left over from file deletes). This is especially important if you have been using the VM for some time, as deleted files do not actually zero the space (just remove the pointers). I recommend using SDelete from SysInternals. Simply run “sdelete -c” to zero out all the deleted file space (experiences may vary!!!).

Once you have cleaned up (and ideally backed up) your VM, The process of migrating to a new datastore and safely shrinking / converting the VMDK files to thin provisioned, is as follows:

  1. Create your new datastore directory on the new drive and specify the location in VMware Server (if required), e.g.
  2. Create a new directory for the VM to be migrated, e.g.
  3. Run the following command:
    “<path-to-vmware-install>\vmware-vdiskmanager.exe” -r “<old-ds-path>\<VM-Name>.vmdk” -t 0 “<new-ds-path>\<VM-Name>.vmdk”
    “C:\Program Files (x86)\VMware\VMware Server\vmware-vdiskmanager.exe” -r “C:\VMs\TestVM\TestVM.vmdk” -t 0 “D:\VMs\TestVM\TestVM.vmdk”
  4. The VM will be converted and copied to the new location with no risk to the original file.
  5. Copy the remaining files from the original datastore location (minus the VMDK / vmdk-flat of course).
  6. Remove the old VM from your VMware Server/Workstation inventory (don’t delete the originals until you have tested the new VM!).
  7. Add the VM back into VMware Server / Workstation using the new datastore location, and start it up, specifying “I moved it” when prompted.
  8. Sit back and enjoy the extra space! 🙂

Note the same process will work for converting VMDK files between all file types, by simply replacing -t 0 with your preferred option from the list below:

0                   : single growable virtual disk
1                   : growable virtual disk split in 2GB files
2                   : preallocated virtual disk
3                   : preallocated virtual disk split in 2GB files
4                   : preallocated ESX-type virtual disk
5                   : compressed disk optimized for streaming

NOTE: You can also run “<path-to-vmware-install>\vmware-vdiskmanager.exe” -k “<ds-path>\<VM-Name>.vmdk” to shrink your vmdk in place, but you will need enough spare space on the same drive to do this (as much as the current vmdk file size if you don’t gain much), you lose the ability to roll back to your original file, and this wont work on thick provisioned disks.

VMware , , , , , , , ,