Disk Thin Provisioning & its ease of use in VMware vSphere has been one of the most used features. Although Thin provisioning has allowed customers to avoid allocating space upfront & saved them tons of space, it does not unallocate space when files are deleted from the Virtual Machine, this is due to the way Windows & other operating systems handle file deletion.

In many cases, the customer will create a Thin Provisioned disk with 80GB & use 10 GB out of it. At this time that Virtual Machine will only use 10 GB on the ESX host. Few days later, he might require to use another 50GB for a temporary purpose. Now he will have the Virtual Machine using 60 GB on the ESX host. After few days he go and delete the files that is occupying the temporary 50GB, then he will discover that the virtual machine does not shrink as he delete files from it & he still has a 50GB of wasted space.

Next step, the customer will call his vendor for a resolution. For that only I have written this article to show how to shrink a windows virtual machine VMDK size after deleting the files in Windows.

Let’s start with a windows virtual machine with two virtual disks mapped to C: drive & E: drive as showing in the images below:

VMware ESX Virtual machine disk usages before filling it up as showing in windows

VMware ESX Virtual Machine VMDK  usages before filling it up

Now I fill the E drive with about 7GB of random files just to grow the disk. See below the virtual machine Thin Provisioned disk used for E drive got larger.

VMware ESX Virtual Server Disk in Windows after filling & before deleting dataVMware ESX Virtual Machine After filling the disks & before deleting the data

Now let’s delete all the temp files I have put into the virtual machine to simulate deleting non needed data from your production virtual machines. Notice in the images below how the E: drive in windows is showing to only use about half  a GB, while it’s still consuming about 7.5 GB on the ESX host.

VMware ESX Virtual Server Disks in Windows After deleting the dataVirtual Machine Disks after deleting data but before trying to shrink it notice it even got larger a bit

The above images illustrate that there is 7 GB is already reserved and not used as the data used to occupy this space was deleted. Although in our example this is a very small disk space & worth nothing in production environment this non used space can be much larger. The summary of the solution is to use sdelete & Storage Vmotion on the virtual machine to free up that unused space. hmmm, I can see you asking how to exactly do that. Well, below is the step by step on how to do that.

1- Download the Sysinternals Suite from Microsoft Website. It can be found at:

http://technet.microsoft.com/en-us/sysinternals/bb842062.aspx

2- Extract the Sysinternals Suite to any folder on the Virtual Machine that you want to free up its unused Thin Provisioned disk. In our example, I extracted it to c:\sysinternalsSuite

3- Run sdelete on the drive you want to shrink, E drive in our case:

c:\sysinternalsSuite\sdelete -c e:

(Note: sdelete will cause the virtual disk to be fully allocated, so you must have enough free space in your data store to handle this extra space usage)

(Note: sdelete is a resource intensive tool & should be used off peak hours)

(Note: sdelete will make sure removed data on the disk vanish for ever, so be carefull when using it.)

VMware vsphere using sdelete to shrink Thin Provisioned Disk

sdelete will take some time to complete so wait till the operation finish & then check the used space by your virtual disk in Virtual Center

Think Provisioned disk will grow when your run sdelete against it

Don’t get mad at me yet. I have already warned you in the note before using sdelete that the disk will grow though the next few steps will fix the situation & will make you happy again.

4- Run Storage VMotion on the Virtual Machine that you want to shrink its disk. Make sure you do a storage VMotion to another Data Store, as you need a real storage VMotion operation to be carried out in order for the size to shrink. In our example, we will storage VMotion our VM from VMFS1 to Storage 1 as shown in the images below:

storage Vmotion the VM to a different datastore

Migrate to a different data store storage 1 in our case

Choose Thin Provisioned format

5- After the storage Vmotion has been carried out successfully, your disk should shrink to almost the same sizing showing in windows as showing in the image below. You might have to refresh your storage view to ensure you get an updated figures.

After Storage VMotion the size shrink

One more note before it comes up by my readers, VMware Tools Shrinking functionality is not support on Thin Provisioned disks. That is the reason behind me not using it in this post. Below is an image which show what you will get in your shrink page of VMware tools if you are using Thin Provisioned disk.

Note VMware tool Shrink functionality does not work for Thin provisioned disks

I hope this help out as many readers as possible. Please leave me a comment with your feedback. Did it work for you? Did you have a problem with it? Do you have a better way of doing the same?