How to Shrink a Thin VMDK on ESXi 5.x Offline
Over time virtual machine guests will grow in size if provisioned as a thin disk due to files being copied or log files being generated, once the files are unallocated (deleted or moved) the vmdk still reserves the location as used thus causing excessive white space. If you have a large datastore with a low cost per gigabyte then this isn’t so much of a problem but if you have a lot of virtual machines on a SSD which is still quite costly per gigabyte then you will want to reduce the size of them (like me).
I highly recommend doing a backup of the whole virtual machine to a separate datastore before preforming these steps. You can use a product called Veeam to do this, there is a free version with limited features but still works perfectly. You can find Veeam here
Firstly check what the allocated and actual size of the guest are:
- Log into shell or console of ESX physical host
- cd /vmdk/volumes/%disk%/%folder%
- %disk% = the disk name
- %folder% = the folder the vmdk file resides in
- ls –lh *.vmdk
- du –h *.vmdk
Note: This process will make the VMDK start expanding to it’s maximum size so make sure you have enough space on that datastore or any guests that reside on it will shutdown!
You can download SDelete by Sysinternals here
- Log into Windows server
- Download SDelete
- Run SDelete
- SDelete – %: (% = Drive letter)
- Shutdown the VM guest, if you don’t you will not be able to get a lock on the vmdk
- vmkfstools -K %vm.vmdk>
- du -h *.vmdk
Should you have any questions, comments or suggestions, please don’t hesitate to comment below. If you like what you have read, please share it on your favourite social media medium.