• How to Zero free space to shrink a Thin Provisioned VMDK

Sometimes you need to shrink a thin provisioned VMDK file after a lot of data has been removed as we all find out the hard way that thin provisioning is great for allowing a disk to grow as data fills it up but with the caveat that the disk will not shrink again automatically when data is removed. Hopefully this quick guide will help you to achieve just that.

Please note this will just reduce the VMDK’s size on the datastore, it will NOT change the provisioned size of a thin disk.

To shrink a VMDK we can use an ESX command line tool vmkfstools, but first you have to zero out any free space on your thin provisioned disk. On Windows guests we can use the sysinternals tool SDelete (replace the [DRIVE:] with the relevant Windows drive letter) you must use v1.6 or later!:

sdelete.exe -z [DRIVE:]

This will fill any unused space on the drive specified with zero-blocks.

Caution: This operation will expand your thin-disk to its maximum size, ensure your datastore has the capacity to do this before you run this operation.

As of v1.6 -c and -z have changed meanings, many instructions say -c zeros free space, this is no longer the case, it zeros the space then fills with random data in accordance with DOD spec: DOD 5220.22-M, the trigger to zero space with 0x00 has changed to -z! On linux guests use:

dd if=/dev/zero of=/[PATH]/zeroes bs=4096 && rm -f /[PATH]/zeroes

Again, replace [PATH] with the relevant path to a location on the target storage device. Next we will shut down the guest OS and SSH into the ESX shell, once in the shell we need to navigate to the VMDK’s datastore -> directory and we’ll check the VM’s actual size:

du -h [DISKNAME].vmdk

Punch all zeroed blocks out of the VMDK:

vmkfstools --punchzero [DISKNAME].vmdk

Check the size again (should now be less):

du -h [DISKNAME].vmdk

Make sure to replace [DISKNAME] with your VMDK’s actual name. That's it, all the free space should now be reclaimed.


This article was last modified: April 24, 2018, 11:42 a.m.

0 Comments

Please log in to leave a comment.

Add or change tags.

A comma-separated list of tags.

Share

Hacker News

Top