Unmap VMware | Updated Script

Update:

I created a new file that works with powershell 5.0 and powercli 6.5 r1. It seems that powercli 6.5 got rid of snapins so it broke my old script.  I have helped many of my clients reclaim TBs of space and I hope it helps you out as well.

The Question

Why does my SAN show I have used 1TB of space but VMware says I am using 500GBs?

So I have been working with a client for the last year and we started getting low on space.  So we started looking at finding Orphaned files and removing old VMs. This is the normal thing you would do on windows. Find the largest files you may not be using anymore and delete it or move it to an external hard drive.

We noticed the space was not going down on the SAN (in this case a EMC VNX2) but when we looked at VMware datastores it was going down. Why?!?!

The Fix

Way back in ESXi 5.0 (August 2011) VMware release a feature called Unmap.  At first I thought “Unmap? like unmap a network drive” but what it actually does is puts 0000 on all the free space in the given datastore.  This allows the storage to be released back to use on any other datastore.

Where can I use this?

  • This is only used on Thin Provisioned LUNs
  • Datastore in VMware using VMFS
  • Some kind of shared storage (SAN, NAS, etc.)

How can I use this?

So you want to free up some space, well there is a couple of ways to do this.

SSH

This is great if you are wanting to test on one host.

/vmfs/volumes # esxcli storage vmfs unmap -l datastore_name

PowerCLI

Selective Host and Datastore 

All Datastores on vCenter

What about Windows servers?

Some may be thinking that well this is all well and good but “what about windows servers they may have dead/grey space as well?” and you would be correct.  NTFS and VMFS do not clean up this dead space. So anytime you delete a file it is really not deleted it is just marked that it can be rewritten.

Powershell

Use powershell to reclaim that space

Sysinternals S-Delete – another windows based tool used for doing the same as above. Many people use this to zero out a drive of a VDI master image or of a VM that will sent to the cloud.

Conclusion

Okay, okay but what is the best way to get it ALL back!

  1. Run SDelete or the PS script on the all Windows VMs (this will create more load on your SAN! so do it after hours)
  2. Run PowerCLI Script on all datastores (this will also create more load on your SAN! but not as bad I found as SDelete)
  3. Sit back and watch your SAN reclaim space!

Real world example:

Reclaimed 20TBs so far on a 140TBs SAN and still going.

 

Leave a Reply