Virtual Machine Preparation (Windows)
Windows does not automatically zero deleted blocks. Microsoft provides a tool that can zero blocks after while deleting a file or zero out the entire free space. This is required to reclaim space back from the virtual disk.
- Download SDelete (http://technet.microsoft.com/en-us/sysinternals/bb897443.aspx)
- run sdelete.exe -z [Drive]
Virtual Machine Preparation (Linux)
Linux does not zero deleted blocks too. There are various tools available to create zeroed blocks. The best known tool is dd which should be available on all systems.
- Identify free space with df
- Fill the free space with dd
vma:/mnt/data # df -h
vma:/mnt/data # dd bs=1M count=8192 if=/dev/zero of=zero
This will zero 8GB of the available 8.2GB (1MB Blocksize * 8192 = 8GB). Please note that you virtual disk file (VMDK) will grow to the full size during the process.
Shrink VMDK File
- Power off the Virtual Machine, or disconnect the virtual Disk you want to shrink
- Connect to the ESXi Host with SSH
- Navigate to the Virtual Machine Folder
- Verify disk usage with du
- Run vmkfstools -K [disk]
- Verify disk usage with du
root@esx3:/vmfs/volumes/ds1/vma $ du -h vma_1-flat.vmdk
7.9G vma_1-flat.vmdk
root@esx3:/vmfs/volumes/ds1/vma $ vmkfstools -K vma_1.vmdk
vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576
Hole Punching: 25% done.
root@esx3:/vmfs/volumes/ds1/vma $ du -h vma_1-flat.vmdk
1.9G vma_1-flat.vmdk