Bobcares

How to fix “Unable to access a file since it is locked” error in VMWare?

by | Oct 20, 2020

Deleting snapshots or consolidating disks of the virtual machines often triggers the “Unable to access a file since it is locked” error on VMWare ESXi hosts.

As a part of our Server Management Services, we help our Customers to fix VMWare related errors regularly.

Let us today discuss the possible causes and fixes for this error.

What is VMWare Error: Unable to access a file since it is locked?

While deleting a snapshot or consolidating disks of virtual machines running on VMWare ESXi hosts, it often triggers the error message “Unable to access a file since it is locked”.

A typical error message may look like:

Unable to access file since it is locked.
An error occurred while consolidating disks: One or more disks are busy.

Another common form of this error is :

VMWare Error: Unable to Access a File Since It Is Locked

Common reasons for this error include:

  • Powered up virtual machine contains some files with tags indicating that they are in use  by other ESXi hosts
  • The backup session fails after adding virtual disks to the backup appliance.

How to fix VMWare Error: Unable to access a file since it is locked?

To fix this error, we need to find the source of a lock and release it. For this, the initial step is to identify the locked files.

    1. First, using an SSH client, connect to the ESXi host for the problem VM.
    2. Now, go to the directory with the virtual machine files:
      cd /vmfs/volumes/VMFS_DATASTORE_NAME/LOCKED_VM
    3. Look for consolidation and file locking errors in vmware.log:
      cat vmware.log | grep lock
    4. The log will contain errors like:
      VigorSnapshotManagerConsolidateCallback: snapshotErr = Failed to lock the file (5:4008)
      2020-09-09T05:07:11.432Z| vmx| I125: DISK: Cannot open disk "/vmfs/volumes/5121c3ff-2303a3a-33bb-12345678221/mun-web01/mun-web01_1-000002.vmdk": Failed to lock the file (16392).
      2020-09-09T05:07:11.432Z| Worker#1| I125: DISKLIB-LIB : Failed to open '/vmfs/volumes/5121c3ff-2303a3a-33bb-12345678221/mun-web01/mun-web01-000002.vmdk' with flags 0xa Failed to lock the file (16392).
      2020-09-09T05:07:11.432Z| Worker#1| I125: DISK: Cannot open disk "/vmfs/volumes/5121c3ff-2303a3a-33bb-12345678221/mun-web01/mun-web01-000002.vmdk": Failed to lock the file (16392).
      2020-09-09T05:07:11.432Z| vmx| I125: [msg.fileio.lock] Failed to lock the file
    5. Here, the file mun-web01_1-000002.vmdk is locked. Use the command below to display the current snapshot chain starting with the specified one to a flat disk:
      vmkfstools -qv10 mun-web01_1-000002.vmdk
    6. Then get the information about the snapshot and its owner (RO owner):
      vmkfstools -D mun-web01-000001-delta.vmdk
      Lock [type 10c000021 offset 242835456 v 856, hb offset 3153920
      gen 3, mode 1, owner 5cbac61a-4b6e32b7-0480-d06726ae7900 mtime 5199410
      num 0 gblnum 0 gblgen 0 gblbrk 0]
      RO Owner[0] HB Offset 3153920 5cbac61a-4b6e32b7-0480-d06726ae7900
      Addr <4, 532, 83>, gen 859, links 1, type reg, flags 0, uid 0, gid 0, mode 600

The RO Owner line shows the MAC address of the ESXi host network adapter that locked the snapshot file. Also, note the Mode value:

  • mode 1 – a read/write lock (for example, of a powered-on VM)
  • mode 2 – virtual disk locked by the backup application.

Now, to find an ESXi server from the MAC address obtained, we can use the following PowerCLI commands:

Import-Module VMware.VimAutomation.Core -ErrorAction SilentlyContinue
connect-viserver mun-vcenter
Get-VMHost | Get-VMHostNetworkAdapter | Where-Object {$_.Mac -like "d0:67:26:ae:79:00"} | Format-List -Property *

It will show the ESXi hostname in the VMHost field.

Further, we can display the ARP table directly from the ESXi host and get IP and MAC addresses of all other ESXi servers in the VMkernel network:

esxcli network ip neighbor list

To unlock a VM file, just restart the ESXi host we found. If we cannot restart the host, we can restart the Management Agent (hostd) in the Maintenance Mode from the host’s SSH console:

services.sh restart

Then try to consolidate disks or delete a VM snapshot again.

[Need any further assistance to delete snapshots or consolidate disks of your virtual machine? – We’re available 24*7]

Conclusion

In short, restarting the ESXi host or Management Agent can help to fix the “Unable to access a file since it is locked”  error. Today, we saw how our Support Engineers fix this error.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.