VMware Thin Disk Reclamation

As I’m sure many of you know, when provisioning your storage in a VMware environment using “Thin” disks, they tend to grow over time. When you delete files inside your VMs, the space isn’t returned to the underlying storage for reuse since the blocks are technically not empty.

Here are a few techniques you can use to reclaim that space across your environment.

HowTo: Reclaim Unused Space From “Thin” Provisioned VMs

Step 1: Zero out free space inside the VM

For your Microsoft Windows based VMs, the OS doesn’t blank out free space by itself. This “feature” allows the use of disk recovery tools in case you erase a file and empty the trash, and also allows the OS to run faster, since it doesn’t have to worry about cleaning up after itself on traditional disks. With thin provisioned VMs however, we want that space back so that we can use it for other VMs!

There is a handy little tool called “sdelete” from Microsoft’s Sysinternals group that has an option to write out all zeros to the free blocks inside your OS. This will allow VMware to actually detect those blocks as free and allow the next step to release that space for other use. You will need to run this tool from a command prompt with administrator privileges.

sdelete-example

Step 2: Release zeroed out blocks from VMDK disk files

Once you’ve zeroed out the blocks from the OS level in your VM, you need to release them from the VM disk file. This is done using a technique called “Hole Punching”. You will need to SSH into an ESXi host, or use the console to perform this task. The command to perform this task is:

vmkfstools -K [vmdk file]
Note: This is to be performed on the VM’s base “.vmdk” file and not the “-flat.vmdk”.

Once the “Hole Punching” is complete, all the empty blocks are released back to the VMFS volume as free space for use by other VMs.

But what about thin provisioned VMFS volumes you might ask? … How do you release those empty blacks back to the storage subsystem? .. read on my friend!

HowTo: Reclaim Unused Space From “Thin” Provisioned VMFS Volumes

Releasing free blocks back to the VMFS volume from a VM (as performed above) is all well and good, but what if we have many thin provisioned VMFS LUNs on the storage subsystem that need their free blocks released? This is especially relevant if you have (against best practices) provisioned your VMs using “thin” disks on underlying VMFS volumes that use “thin” storage on the back end (sometimes referred to as “thin on thin”).

As of VMware ESXi 5.x there is a new command to help you out.

From the ESXi console (or an SSH session), you can run the following command to release the free blocks from a VMFS volume back to the storage subsystem.

esxcli storage vmfs unmap -l [vmfs volume label]

After running this command, all free storage blocks from that volume are returned to the storage subsystem 🙂

Thanks for reading, I hope this was helpful to some of you!

-Paul

About Paul Reed