Unable to delete leftover VM files from Datastore due to file lock issues
book
Article ID: 395679
calendar_today
Updated On:
Products
VMware vSphere ESXi
Issue/Introduction
Deleting VM files that aren't attached to any VM from the datastore fails with file lock errors.
Resolution
Connect to any of the ESXi hosts connected to the datastore with the locked files via SSH session.
Find the IP address of the host holding the lock by running vmfsfilelockinfo on the VM file for example: VMDK flat, delta, or sesparse file for VMFS, or the .UUID.lck file for vSAN. vmfsfilelockinfo -p /vmfs/volumes/<Datastore UUID>/<VM folder>/<VM file name>
Example Output:
vmfsfilelockinfo Version 2.0
Looking for lock owners on "VM file name" 'VM file name" is locked in Exclusive mode by host having mac address ['##:##:##:##:##:##'] Trying to use information from VMFS Heartbeat
Host owning the lock on file is 10.##.##.10, lockMode : Exclusive Total time taken : 4.332670005038381 seconds.
Note the IP address from the above output and confirm which host in the environment is holding the lock on the files.
Log in to the SSH session of the above-noted host and try to delete the files from that host.
If in case you the issue persists due to file lock errors, reboot the ESXi host, then attempt to delete the files.