VM state invalid in vCenter inventory due to file lock from an ESX host
search cancel

VM state invalid in vCenter inventory due to file lock from an ESX host

book

Article ID: 424735

calendar_today

Updated On:

Products

VMware vCenter Server

Issue/Introduction

In VMware vCenter, a virtual machine (VM) may appear in an "invalid" state within the inventory. You may find yourself unable to re-register the VM because a specific ESXi host is holding a file lock on the VM’s configuration (vm-name.vmx) file. This issue can occur even if the host holding the lock is currently in maintenance mode.

Environment

  • VMware vSphere ESXi (All Versions)
  • VMware vCenter Server (All Versions)

Cause

An ESXi host maintains an active lock on the VM files, preventing other hosts from registering or managing the object. This typically happens if a VM process remains running on a host creating a mismatch between the host's actual state and the vCenter inventory.

Resolution

To resolve this issue, you must identify the host holding the lock and re-register the VM from that specific host.

  1. Identify the host holding the lock:

    Follow standard procedures to identify the MAC address of the host holding the lock by running vmkfstools -D against the VM's .vmx file and reviewing the vmkernel.log.

    vmkfstools -D /vmfs/volumes/<Datastore_Name>/<VM_Folder>/<VM_Name>.vmx
    tail /var/run/log/vmkernel.log

    Find the MAC Address of the host holding the lock as the last portion of the UUID. Example:
    <timestamp> In (182)| vmkernel: gen 37, mode 1, owner ########-########-####-001122334455 mtime 3890942

    This would equate to a MAC Address of 00:11:22:33:44:55 in the above example.

    Refer to Device or resource busy / file is locked error when making changes to a file on an ESXi datastore for further details.

  2. Access the host:

    Log in via SSH to the ESXi host identified by the MAC address.

  3. If the host is in maintenance mode, it can exit maintenance mode. If the host is not in MM, skip this step.
        
    Select the host and in the actions pull down, select Exit Maintenance Mode.

  4. Register the VM via CLI or by browsing the datastore to the VM folder and selecting the .vmx file and clicking Register VM:
        
    To accomplish this via the CLI, the following command registers the VM on the connected host:

    vim-cmd solo/registervm /vmfs/volumes/<Datastore_Name>/<VM_Folder>/<VM_Name>.vmx

  5. If the option to register fails or is greyed out from the file browser, the VM may show as invalid in the VC inventory.  If so, remove that invalid VM entry from the VC inventory.  The registration can then be attempted again but in some cases the lock-owning host might need to be rebooted.

Additional Information