Reclaiming space from deleted files on a Thin-Provisioned Linux VMDK (on VMFS) when Guest UNMAP fails or is unavailable
search cancel

Reclaiming space from deleted files on a Thin-Provisioned Linux VMDK (on VMFS) when Guest UNMAP fails or is unavailable

book

Article ID: 446393

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

  • Files were deleted on a thin-provisioned Linux virtual machine (VM) residing on a VMFS datastore.
  • Guest-level UNMAP fails to reclaim space or is unsupported by the guest OS.
  • The used space reported within the guest OS decreases, but the VMDK footprint on the datastore does not shrink.

Environment

VMware vSphere ESXi 8.x

Cause

When a file is deleted in a Linux environment, the operating system does not actively erase the underlying data from the drive, as doing so requires significant processing overhead. Instead, the file system simply removes the index pointer and flags the associated storage blocks as available for future use. Consequently, the original binary data remains intact on the virtual disk until it is eventually overwritten by new operations.

Resolution

  1. Ensure there are no active snapshots on the virtual machine.

  2. Zero out unused blocks on the Linux Guest OS. This can be achieved using a guest-level utility, if available, or via the dd command:
    dd if=/dev/zero of=/zeroes
    rm /zeroes
    Note: the dd command will create a file of zeroes named "zeroes" which consumes all free space on the disk. This causes the thin disk to inflate to its full provisioned size. The file is then deleted.

  3. Power off the VM, connect to the ESXi host via SSH, login as root and run:
    vmkfstools --punchzero /vmfs/volumes/<datastore_name>/<VM_name>/<VM_name>.vmdk

    Note:
        Replace /vmfs/volumes/<datastore_name>/<VM_name>/<VM_name>.vmdk with the full path to the VMDK. The command must be run against the descriptor file (.vmdk), not the -flat.vmdk file.
        If a virtual machine has more than one disk, the command must be run against each disk individually.
        The time to complete the process will vary with the size of the disk and number of blocks to be reclaimed.