Note: Reclaiming disk space only works when the blocks on your virtual disk are not in use by the Guest OS.
Reclaiming disk space is a two steps process
The first step is to delete the blocks on the Guest Operating System then reclaim space on the VMFS datastore. Be sure to follow the bellow steps in order.
Step 1: Delete the blocks on the Guest OS
Windows Operating System
- Download SDelete Command Line Tool available at https://docs.microsoft.com/en-us/sysinternals/downloads/sdelete
Note: SDelete -z will cause the guest OS to use up 100% of the available space disk during this process while zeroing free space. This will lead to a temporary increase in used space on the datastore.
- Open an elevated command prompt.
- Run this command
sdelete.exe -z drive_letter:
Note: Replace [drive:] with the target disk or partition. Note that when you have multiple partitions on a single virtual disk, you need to do this on all partitions for it to be effective. Otherwise, reclamation will only be partial because not every data block will be zeroed.
Linux Operating Systems:
Linux has different ways to delete the unused blocks, the most common method is to fill the free space with a file of zeroes using the dd command:
$ dd if=/dev/zero of=/mounted-volume/zeroes && rm -f /mounted-volume/zeroes
Notes:
- Be sure to shutdown all services which writes to the target volume to avoid running out of space
- If there are multiple partitions on a single virtual disk, same step needs to be performed on all partitions. Otherwise the reclamation will be partial because not every data block will be zeroed.
Step 2: Reclaim space on VMFS
- Power off the virtual machine.
- Log in to the ESXi host using SSH and root credentials.
- Navigate to the directory that contains the virtual machine disk using the command:
cd /vmfs/volumes/DATASTORE_NAME/VM_NAME
- Run this command:
vmkfstools -K disk_name.vmdk
Notes:
- The file used here is descriptor file .vmdk file not the data file -flat.vmdk
- The process may take longer depending on the size of the disk and number of blocks.