Cannot deploy a virtual machine from a template because the template VMDK file is locked
search cancel

Cannot deploy a virtual machine from a template because the template VMDK file is locked

book

Article ID: 337545

calendar_today

Updated On:

Products

VMware vCenter Server VMware vSphere ESXi

Issue/Introduction

Symptoms:
  • Cannot deploy a virtual machine from a template
  • The template's <vm name>-flat.vmdk or <vm name>.vmdk file is locked by a running virtual machine
  • The VMDK file is not found
  • When deploying a template the option to Edit virtual Hardware (Experimental) is selected and the disk size has been modified


Resolution

A virtual machine deployed from a template locks the template's VMDK files if it is incorrectly configured to run on the template's virtual disk and VMDK file instead of its own. The lock prevents other virtual machines from being deployed from the template.
 
You must determine if the template's VMDK file is locked by another virtual machine, and if so, release the lock on the files.
 
Caution: Since a virtual machine was running on the template's disk, there may have been unwanted changes to the disk. As such, a good backup and recovery plan is essential to production environments.
 
To determine if the template's VMDK file is locked by another virtual machine:
  1. Login as root to the ESXi host
  2. Change to the working directory of the template
  3. Run the command:  
    vmkfstools -D <virtual disk file> | tail -f /var/log/vmkernel.log | grep -i owner
     
  4. If there are (non-zero) numbers and letters near the end of the output, a MAC address has been associated with this VMDK and another virtual machine has a lock on this file. If there are zeros at the end of the output, the VMDK file is not locked by another virtual machine.
To release the lock on the template's VMDK file:
  1. To show which virtual machine on a single host has the lock, run the command:

    grep -lr <virtual disk file> /vmfs/volumes/*/*/*.vmx

    Note: Record the full path to the virtual disk file. If this fails because of locked files try one of the methods below. This may be the case if the virtual machine disks are on storage shared between multiple hosts:

    Alternate methods:

     
    • grep vmx /etc/vmware/hostd/vmInventory.xml | sed -e 's/>/</g' | awk -F\< '{print $3}' > vmx;
      IFS=$(echo -en "\n\b"); for i in `cat vmx`; do echo grep -H vmdk $i; done
    • Connect-VIServer -server localhost
      Get-Vm | Get-Harddisk | Where {$_.Filename -match "<diskname>"} or 
      Get-Vm | % { if ((Get-Harddisk -VM $_).Filename -match "<diskname file>") {$_ }}
  2. Power off the virtual machine that has the lock. If you cannot power off the virtual machine, seePowering off an unresponsive virtual machine on an ESX host (1004340).
  3. Edit the virtual machine's settings and remove the virtual disk, but do not delete it.
  4. To connect an existing disk:
    • In the Add Hardware Wizard, click Hard Disk > Next.
    • Select the type of storage for the virtual machine’s disk.
    • Click Next > Use an existing virtual disk.
    • Browse to the path of the virtual disk file identified in Step 1.
    • Click Next. --> Finish


Additional Information

テンプレートの VMDK ファイルがロックされているためにテンプレートから仮想マシンをデプロイできない
由于模板 VMDK 文件被锁定,无法从模板部署虚拟机