Reclaiming disk space from thin provisioned VMDK files on ESXi 6.5 & 6.7

Reclaiming disk space from thin provisioned VMDK files on ESXi (2136514)

Virtual Machines (VM) using thin provisioned disk do not see size decrease after deleting files from the Guest Operating System. 

Deleting data from Guest OS only removes the data from the file allocation table but does not zero the blocks. As a result, the ESXi Host still sees the blocks in use even after deleting the data.

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

  1. 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.

  1. Open an elevated command prompt.
  2. 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

  1. Power off the virtual machine.
  2. Log in to the ESXi host using SSH and root credentials.
  3. Navigate to the directory that contains the virtual machine disk using the command:
cd /vmfs/volumes/DATASTORE_NAME/VM_NAME

  1. 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
 If the step One was completed the space wasn't reduced, we need to perform the second step. Otherwise, the Virtual Machine will not work. RECLAIM space of VMFS will work 100%

  1. You can also reclaim the space by storage migration and selecting the appropriate format.  
Reference Article: https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vcenterhost.doc/GUID-A15EE2F6-AAF5-40DC-98B7-0DF72E166888.html 

  1. You can also solve this issue by cloning the VM. Please refer the following steps: 

            VMware Doc: https://docs.vmware.com/en/VMware-vSphere/7.0/com.vmware.vsphere.vm_admin.doc/GUID-1E185A80-0B97-4B46-A32B-3EF8F309BEED.html 

Comments

Popular posts from this blog

Zabbix Server is not working: the information dispaly may not be current

How to install VNX Launcher that has embedded java and Firefox

DHCP FAILED APIPA IS USED