Power On virtual machine – Unable to access file since it is locked

Several times in the past few weeks I have ran into virtual machines that do not power on because of locked files. Steps to troubleshoot this issue are described in KB10051: Virtual machine does not power on because of locked files. While looking into this topic, I found the following article on vi-tips.com Could not power on VM – lock was not free, which describes the same issue. My issue was encountered on several ESXi 5.0 Update 1 hosts, and according to this vi-tips.com article the issue also exists on ESXi 4.1.

The vi-tips.com post includes several screenshots of how to isolate/troubleshoot this issue. After a few steps, you can use vmkfstools -D /vmfs/volumes/sanvolname/filename-flat.vmdk to determine the MAC address of the VMKernel interface maintaining the lock. A little bit of PowerCLI goes a long way into finding which host uses this interface:

[cc lang=”Powershell”]
Function Get-VMHostNameByMac ([string]$macAddress) {
#The MAC address passed to this function does not need separators, we will remove them if provided
$macAddress = $macAddress.Replace(“:”,””).Replace(“-“,””)

#The MAC property returned by the Get-VMHostNetworkAdapter cmdlet will have a colon separator, so we will remove it for comparison purposes
Get-VMHost | Get-VMHostNetworkAdapter | where {$_.Mac.Replace(“:”,””) -eq $macAddress} | select-Object VMHost, Name, MAC
}
[/cc]

Here is example usage of this command:

Get-VMHostNameByMac '001ec9123456'

Once the locking VMKernel interface is located, we can continue troubleshooting. The vi-tips.com article suggests cold migration of the VM to the locking host and powering on the virtual machine on that host — but I was unable to get that option to work. However, I found that restarting the management agents on the locking host would resolve my issues. Once the management agents were restarted I could power on the VM using any host.

This entry was posted in Scripting, Virtualization. Bookmark the permalink.

Leave a Reply

Your email address will not be published.

*

Notify me of followup comments via e-mail. You can also subscribe without commenting.