I’ve seen a number of posts on the VMTN forums as well as had discussions with folks regarding reclaiming disk space with Storage vMotion so I thought it made sense to do a quick write-up on how this process works.
The situation is unfortunately all too common – virtual machines are deployed and treated like a physical machine in terms of resource all0cation. In the physical world it is common to see VMs with multiple processors, lots of RAM, and at least 73GB disks (of which maybe 25GB is actually used). Folks often have a hard time letting go of that configuration, and so they’ll bring it into the virtual world. While it is easy and relatively painless to reduce CPU and memory, reducing the size of a virtual disk to reclaim some space on your VMFS partition isn’t as straightforward. Still easy, just not straightforward.
You have two solutions to the problem depending on how you want to reclaim the space:
1) Use VMware Converter to V2V the VM and resize the disk. This will reduce the size of the disk both in the guest and on the VMFS partition, but requires a brief amount of downtime to swap between the original VM and the converted VM.
2) Use Storage vMotion along with thin provisioning in vSphere to resize the disk on the VMFS partition but leave it the original size in the guest. The size of the disk will grow as data is written to the VM.
Most of the time option 2 works without a problem. But what about the case where you previously had data on the drive and deleted it and wish to reclaim the space. In that case the Storage vMotion will likely not be able to reclaim the space. Why? Because the blocks that had been previously written to the drive need to be zeroed out first.
The easiest way to do that is to use a tool like SDelete. SDelete is capable of scanning a drive and zeroing out blocks from deleted files so that they can be reclaimed as free space. Use the following command to zero out the free space:
Sdelete.exe -c c:\ <– Replace the c:\ with the appropriate drive letter.
In this example we have a VM that has a thick provisioned 25GB C: drive and nearly all of the space on disk was consumed. I deleted some old data and now show 15.7GB free inside the VM. I then ran SDelete as listed above and would like to convert the VM to thin provisioned and reclaim some space. Here is how it looks now:
I then right click on the VM, choose Migrate, and select that I want to Change Datastore. Once you get to the Disk Format screen, remember to select the “Thin provisioned format” option as seen below:
After the Storage vMotion is complete, the disk is now thin provisioned and takes up much less space:
If you’re going to use thin provisioning in vSphere, make sure you have the proper alerts setup in vCenter to notify you when space is getting tight. It’s a great way to better utilize disk space as well as reclaim space without downtime.