Thinning (shrinking) VMDK disks on ESXi / vSphere Linux Guests
Note: "Shrinking" is often used interchangeably to refer to the process
of reducing the size of a thin-type disk file. VMware uses the term
"shrink" to refer to reducing the underlying size of the disk available
to the guest, and "thinning" as the process most tend to use of
recapturing unused space without altering the underlying available
size.
Since ESXi does not support vmtools-based shrinking on Linux guests, the following steps must be used. See reference link below for more information.
(if possible) Stop all disk write-intensive applications and services as the following steps will momentarily fill the target volume
Defragment volume(s) on target VMDK and ignore any errors as symlinks/device files/etc. cannot be defragmented.
# USE sudo IF NECESSARY IN YOUR CONFIG!
e4defrag /
# or e4defrag /mnt/MOUNTVOLUME
- Zero-fill all unused space:
dd if=/dev/zero of=/mnt/MOUNTVOLUME/zeroes bs=1M; sync; rm /mnt/MOUNTVOLUME/zeroes
Shut down & power off guest
SSH to the ESXi host and issue these commands:
# Check current vmdk allocation
du -h /vmfs/volumes/volumename/vmname/vmname.vmdk
# Shrink it
vmkfstools -K /vmfs/volumes/volumename/vmname/vmname.vmdk
# Check again to verify shrinkage
du -h /vmfs/volumes/volumename/vmname/vmname.vmdk
- Power on the guest
Source
https://kb.vmware.com/s/article/1002019
Deletion of files in most file systems will not completely remove
them; merely file tables will be altered. Use of freeware secure file
deletion utilities are useful, such as Eraser or SDelete to zero out
the space to 'zero' the free space on the volume, effectively clearing
the free space of data. It is then, that the disk can be properly
thinned. You can then use the vmkfstools -K command (ESXi/ESX 4.1 and
later) to complete the block reclaim or use Storage vMotion to migrate
the virtual machine to a datastore with different VMFS block size.