VMware ESX 4 Reclaiming Thin Provisioned disk Unused Space

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: newer versions of sdelete might use the -z for zeroing rather than -c, please check what is the right flag at the particular version you are using)

(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?

Comments

  1. What’s the option for SMB customers having Essentials or Essential plus license? Without storage vMotion?

    Any options?

    Thanks
    Vladan

  2. Hi Vladan,

    Although I have not tried this without storage vMotion, you should be able to achieve the same result by replacing the Storage vMotion with the following procedure:

    1- Shutdown the Virtual Machine after you had run the sdelete on it.
    2- Migrate the Virtual Machine to another VMFS datastore.
    3- Power on the Virtual Machine.

    The above procedure should do the trick for customers who does not own storage vMotion, though it requires a bit of downtime. Hmmm, as you mentioned SMB & they will not spend for storage vMotion then I guess they could handle a bit of downtime.

    Did someone say this can be another reason to sell storage vMotion?!?!

    I hope that help, & keep in touch.

  3. Hi,

    The solution above is good, however do you know if there a a way to programmatically tell the vmfs file system that certain sectors are ununsed, in windows terminology make a portion of the file sparse, in linux terminology create holes in a file.

  4. I have tried this (and my own program to create a huge 0-contents file and then delete it) on the latest ESX 4.1 and vSphere 4.1, and it doesn’t work any more. This worked with previous versions no problem, but with the latest versions it doesn’t appear to compact disk blocks containing 0s any more.
    Any idea what might have changed that is stopping this working?

    Thanks!

  5. If VM is deleted on ESX, will the space automatically released on the storage frame?

  6. Hi Cindy,

    Yes it will be released immediately as long you have chosen to delete it from disk not just delete it from inventory.

    Enjoy,
    Eiad

  7. There must be a better tool than sdelete that can intelligently zerofill only the freespace that needs zerofill.

    The problem with sdelete is that it wastes time/resources by basically converting your disk from THIN to THICK and back to THIN by doing zerofill on free space that hasn’t been allocated yet. SDelete ideally should not try to zerofill free space that hasn’t been allocated yet.

    Is this even possible? If a guest OS tries to scan unallocated freespace for zerofill sectors, does that cause Vmware to commit storage for those sectors? Or does vmware only commit storage to the guest during write operations, not read operations?

  8. Hi Satyen,

    As of my understanding, we are only committing on write. I will leave my answer here so others can slap me if I am wrong on this :).

    Regards,
    Eiad

  9. Hi,

    I wonder if VAAI will significantly speed up the sdelete process on thin disk before storage vmotion to reclaim space?

    Thanks.

  10. To be honest I am not sure as I have not tested that but it might. Though the sdelete process is mainly run by windows so the effect might not be great.

    Regards,
    Eiad

  11. Excellent post. I will be trying this out very soon. We have been looking for a way to do this for months now. We have tried using VMconverter, which has the ability to shrink the disk and does actually work well, however, it takes FOREVER and the VM has to be powered off.

    Thanks!

  12. that was really help full but what if a virtual machine is an SLES 11, is there an utility like sysinternals suite for SLES 11

  13. Spencer says:

    I’ve just tried this on an ESXi 4.1 Update 1 server and no joy. I sdelete -c and storage vMotion and I’m still left with a fully provisioned disk!! What now? It took ages as well. I could try to move it back? Or shall I run sdelete -z to “Cleanse Free Space”?

  14. Hi Bryan,

    I am sorry for the late reply, to be honest I did not try this on Linux yet my self. Though something like DD on Linux probably can simulate with sdelete can do on Windows.

    You might want to look at the following post http://www.feyrer.de/g4u/#shrinkimg

    Remember your claimed space will not appear till you migrate the VM across datastores either using storage VMotion or Cold migration.

    As I mentioned I have not tried this before, so you might want to test it on a test system first and revert back to us of how it goes for you. If all fail you can use VMware Converter to shrink it but that will require some downtime.

    Enjoy,
    Eiad

  15. Jesse Shumaker says:

    Spencer did you find a solution to what you were asking on the -Z switch? I’m in that situation where I didn’t have the forsight to see that this would bloat my vm’s after running that sdelete -c on all the partitions which now leaves me in a bind (since the remote datastore isn’t large enough to handle the full sized vm). When trying to do remote vm replication since the vm’s show up as full size.

  16. Thomas Fuk says:

    As Julian Field said above. Unfortunately, it does not work with vSphere 4.1 (tested on ESXi 4.1 update 1). Does someone find a solution for free unused space on thin disk or it´s now impossible?
    Thanks, TF

  17. Hi All,
    Thank you Eiad for the post.
    we have ESX 4.1 update 1 and i used the V-locity from diskeeper.com insted of the sdelete , you can get a free 30 day version from thier website.
    It totaly did the sdelete job in a very easy and secure way.
    i have tested that on one vm so far, and i am working right now on the others .

    Regards

  18. Seems to be fixed in vSphere5. I use vOptimizer Pro to do alignments and resize operations. If you run resize with total disk size quota set to size of Windows partition it will zero out un-used space and space will be reclaimed by VMFS.

    This did not work with ESX 4.x only was I was able to get space reclaimed was to run SDELETE -c –z and then storage vMotion to NFS datastore.

  19. The only thing I found working every time is
    1 image out,
    2 make new thin disk
    3 image back

    sucks btw :)

    if it’s data Partition copy data to new thin drive from
    1 d: til e:
    2 change drives letters

    another good reason to have OS and data on separate partitions. :)

  20. Hi,
    How Can i use Dell Power Vault 114t Tape Drive scsi, with ESX 4.0?
    Shall i connect it to any ESX server?
    How multiple VMs located on other Vcenter server can use this tape drive?

    Regards & Thanks,
    Aamir

  21. I have to remark an important point : Storage Vmotion will work correctly only if the size block between the both datastores are the same …

  22. Actually, I found that space was reclaimed ONLY when I storage vMotioned to a datastore of a DIFFERENT blocksize..!

  23. SSH(or use ALT+F1 at the console then type unsupported) into your host containing the disk you want to shrink.

    Cd to /vmfs/volumes/(YourDatastoreName)/(YourVMsName).

    Locate your the name of the vmdk you want to shrink.

    Then the command is vmkfstools -i (YourDisk).vmdk -d thin (NewDiskName).vmdk

    Edit settings in your VM and attach the new disk you just made and remove the original(but don’t delete it)

    After seeing that it boots. Then you are free to delete the original.

  24. For version 4.1, we ran into the issue where space was not recovered. This seems to be the case when the source and target datastores have the same block size. If they have different block sizes, the vmotion process reclaims the space that was zeroed out by sdelete.

  25. Hi All,

    For reclaiming thin provisioning space you no need to use that SDELELTE utility. Simply you can migrate the Guest VM to a differenct datastore.

    **********Wishing you all the best**************

  26. Another option would be to export the VM to OVA, then re-import it using thin provisioning.

  27. Tony G says:

    You have to use sdelete or some other tool, I just tried it on esxi4. However I used CCleaners disk wipe and it worked fine and seemed faster than sdelete. I’m running sdelete now, seems more elegant than using ccleaner (don’t know about licence and such).

    I’m wondering if defragmentation has anything to do with releasing disk space?

  28. Tony G says:

    Doesn’t work on all servers though. I also tried defragging, which some people recommend before sdelete. I think the only posibility is to create new disks, copy all data and then remove them, which means downtime.

  29. Makes sence, since when you delete something in a virtual machine, the data is only marked as deleted but is still on the virtual hard drive (remember you can use undelete tools to recover deleted data).

    VMWare will never know that data is deleted, since it reads the virtual harddrive and just sees data isntead of zeroes.

    Ccleaner/sdelete makes the already deleted data to zeroes, after that, VMWare can recognize what data is in use in the virtual hard disk, and what is not… (zeroes).

    To bad VMWare can’t auto shrink disks, or can it, in 5.0 or 5.1?

  30. Found it, worth noticing, 5.1 supports “automatically shrink” now;
    http://www.vmware.com/files/pdf/techpaper/Whats-New-VMware-vSphere-51-Storage-Technical-Whitepaper.pdf

  31. Hi Peter,

    Quick note on automatically shrink introduced in vSphere 5.1 that it only works with the new SE (Sparse Disk) format newly introduced in vSphere 5.1 and its only use case at the moment is VMware View. Hopefully it will be used more widely in future releases.

    Thanks,
    Eiad

  32. A very easy way to do it is to clean the free space on a VM with a “safe delete tool” (ccleaner for windows has it) and then to compact/shrink it normaly with VMware. Takes no time!

  33. It looks like sdelete -z is what you want to use, not -c.
    The current version of sdelete has -z as the “zero” option and -c as the “cleanse” option. The example used in this article has an older version of sdelete with those options switched.

    Make sure you choose the correct option (-z or -c) for your version of sdelete (run sdelete.exe /? to see the option definitions). You want the zero option, which is -z in newer versions.

  34. Thanks Brian for your comment, I have just added a note to the article to note that to other readers.

    Thanks again,
    Eiad

  35. sarathkumar says:

    could u please tell that how to partitioning the Datastore of VMFS1 is 199.75 GB into three storage( eg.. storage 1 is 100GB, storage 2 is 50GB and storage 3 is 49.75GB ) ?

    thanking u in advance.

Trackbacks

  1. [...] the original post: VMware ESX 4 Reclaiming Thin Provisioned disk Unused Space … Plurk This Post Delicious Digg This Post MySpace Ping This Post Reddit This Post [...]

  2. [...] Storage Provisioning (VMware) VMware ESX 4 Reclaiming Thin Provisioned disk Unused Space (Virtualization [...]

  3. [...] Storage Provisioning (VMware) VMware ESX 4 Reclaiming Thin Provisioned disk Unused Space (Virtualization [...]

  4. […] Choices (Virtualization Evangelist) Pointers for using thin-provisioned disks (Virtualization Pro) VMware ESX 4 Reclaiming Thin Provisioned disk Unused Space (Virtualization Team) Provision a Thin Provisioned Standby LUN For vSphere Thin Provisioning […]

Speak Your Mind

*

Sponsors