Introduction
Some things should be simple, shrinking a thin provisioned virtual disk should be one of them, it’s not. N.B. This will just reduce the VMDK’s usage on the VMFS datastore NOT resize 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.
Windows
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
!
Linux
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 (will now be less):
du -h [DISKNAME].vmdk
Of course, replace [DISKNAME]
with your VMDK’s actual name. There we have it, all that free space, now reclaimed.
Why not follow @mylesagray on Twitter ↗ for more like this!