thelowercasew.com
24Jan/1113

Reclaiming disk space with Storage vMotion and Thin Provisioning

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:

25GB Consumed + 2GB for VMkernel swap

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:

Thin provisioned format

Thin provisioned format

After the Storage vMotion is complete, the disk is now thin provisioned and takes up much less space:

Size after svMotion

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.

Comments (13) Trackbacks (3)
  1. Or use the VMware Tools shrink option I described in this article a year ago:
    http://www.yellow-bricks.com/2009/07/31/storage-vmotion-and-moving-to-a-thin-provisioned-disk/

    Cool stuff though,

  2. VMware have screwed this bit of using vMotion to thin out disks in 4.1. It doesn’t work any more :-(
    Worked great in 4.0. Now the only way I can find is to use the VMware Converter to re-import them and change the disk size ever so slightly so it does a file-based volume copy.

  3. Duncan – Thanks for the comment. It’s true that the Shrink option can be used for this as well as long as the disk is already thick provisioned. The Shrink option is unavailable if the disk is thin provisioned. If you’ve cleaned up space on a thin provisioned disk and want to reclaim it then you need to use SDelete.

    Julian – I performed the steps in this blog post on a VM that is on a host running ESX 4.1 (not ESXi) and I was able to reclaim the space several times without issue. I haven’t heard of something changing in 4.1 to prevent this from working.

    • Are you using datastores formatted in different ways or the same way?

    • I have a thin provisioned that I want to reclaim… What do u mean by using just sdelete ?

      • Hey George,

        SDelete is a tool that can be used to zero out blocks of data that have previously been deleted off of a disk. If you have a virtual machine with lots of free space after deleting files, you can simply run SDelete using the syntax listed above and it will zero out the blocks.

        Then you can use Storage vMotion to move your thin provisioned VM to another datastore (with a different block size – see Duncan’s post above) to reclaim that unused space and shrink the VMDK file.

        Is that what you’re asking? This article is intended to provide instructions on how to do this so I’d recommend re-reading it and then posting back if you have any issues.

        Matt

  4. This is one of the biggest pitfalls of thin provisioned disks. Depending on how much you overcommit a datastore you run the risk of some numbskull temporarily using a lot of space, and unfortunately, reclaiming the space back isn’t easy. I’m an advocate for both thin provisioning and PROPER disk sizing :) . Thin provisioning isn’t a cheap fix for bad p2v where the disk wasn’t properly resized IMHO.

  5. Thanks for writing this article, it came in handy today.
    @sixfootdad

  6. Just tried the sdelete option and a storage vMotion on ESXi 5 with VMFS5 datastores … and it worked well! I was a bit afraid as the block sizes are all identical on newly created VMFS5 datastores, but it did the trick.


Leave a comment


Subscribe without commenting

Go to top ↑