Backtrack:  
 
by lunarg on December 12th 2014, at 12:52

When you have some VMs with thin provisioned disks, you may have noticed that these will continue to grow, and never shrink, even after cleaning out data from within the VM. Currently, VMware does not have automatic space reclamation, unless you're running a SAN which supports this (and you have the necessary components installed, such as EqualLogic's HIT-kit). Luckily, there are some tools to allow you to reclaim unused space from your virtual thin disks. The only downside is that you have to power off the affected machines.

Step 1: "really" deleting space

Reclaiming disk space only works when the blocks on your virtual disk are really empty. Deleting data usually only removes the entries from the file allocation table but does not zero the blocks. As a result, ESX will still think the blocks are in-use. There are a few tools available to do this on Windows- and Linux-hosts.

Windows

Download SDelete. This command-line tool has a powerful feature which can track and zero unused blocks. You won't notice a difference in used disk space from within your VM, but this will enable VMware to track unused blocks and release them back to your datastore, effectively shrinking your thin provisioned disk.

Open an elevated command prompt and run SDelete:

sdelete.exe -z [drive:]

Replace [drive:] with the affected disk or partition. Note that when you have multiple partitions on a single virtual disk, you need to do this on all partitions for it to be effective. Otherwise, reclamation will only be partial because not every data block will be zeroed.

Linux

Linux has a different approach. Depending on your filesystem, there are several tools out there, but one that works everytime is by filling free space with a file of zeroes.

First, be sure to shutdown all services which write to the volume you want to shrink as to avoid problems with them running out of free disk space. Next, use dd to completely fill free space with zeroes:

$ dd if=/dev/zero of=/[mounted-volume]/zeroes && rm -f /[mounted-volume]/zeroes

Replace [mounted-volume] with wherever you've mounted the volume. Note that when you have multiple partitions on a single virtual disk, you need to do this on all partitions for it to be effective. Otherwise, reclamation will only be partial because not every data block will be zeroed.

Step 2: reclaim space in ESX

When step 1's done, you're ready to really reclaim disk space. This is done by "punching out" zeroed blocks in the virtual disk's VMDK file.

First, power off the affected VMs and log into any ESX server with access to the VMFS datastore which has the VMDKs to shrink. Cd to the datastore and volume. Next, launch vmkfstools:

vmkfstools -K [disk].vmdk

Replace [disk] with the disk name. For ESX, don't reference the flat VMDK (usually called disk-flat.vmdk). You have to reference the descriptor file (disk.vmdk).

Depending on the size of the disk, this can be a lengthy process. When finished, all blocks that were previously zeroed from within the VM will now be gone from the VMDK and space will have been reclaimed.

Note to VMware Horizon View users
Reclamation of disk space won't apply to VDs until your next recompose.
Note 2
As said in the first sentence of this article, this only works with thin provisioned virtual disks.
 
 
« August 2017»
SunMonTueWedThuFriSat
  12345
6789101112
13141516171819
20212223242526
2728293031  
 
Links
 
Quote
« When a bird does poo poo in your eye, be happy elephants don't fly. »