Thin provisioned disks are a great feature to save capacity as you virtual machines filesystem will never use the full capacity. I do not know a single system where you do not have at least 10GB of free space for OS disks. I am not considering databases, applications or fileservers which will grow constantly. Having thin provisioned disk is usually no longer a performance problem so it is a valid design choice even in production.
A common issue with thin disks is that the size will grow when required, but never shrink. When you require the capacity only once you might want to get it back from the virtual machine. This post describes how to reclaim unused space from the virtual machine.
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
- run sdelete.exe -z [Drive]
Wait a couple of minutes until the process is finished. Please note that you virtual disk file (VMDK) will grow to the full size during the process.
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
[email protected]:/vmfs/volumes/ds1/vma $ du -h vma_1-flat.vmdk 7.9G vma_1-flat.vmdk [email protected]:/vmfs/volumes/ds1/vma $ vmkfstools -K vma_1.vmdk vmfsDisk: 1, rdmDisk: 0, blockSize: 1048576 Hole Punching: 25% done. [email protected]:/vmfs/volumes/ds1/vma $ du -h vma_1-flat.vmdk 1.9G vma_1-flat.vmdk