VMware vSphere: Cannot register a virtual machine in inventory: A virtual machine or template having the same name is already registered

Hi,

a customer had the problem that a virtual machine is shown as invalid or orphaned. After removing from inventory (not from disk) he couldn’t register the vm again: “A virtual machine or template having the same name is already registered”

This could have multiple causes:

Some process are still running which access files from the virtual machine an one ESXi Host. Connect to the Host by ssh.

Normally you can determine the host which locks the file by the vmkfstools command. Where owner is the Host which locks the files. In this example 005056d4f557 is the MAC Address of the Management interfaces of the ESXi Host which held the lock. If the MAC is equal to 000000000000 the file isn’t locked.

~ # vmkfstools -D /509bbbf5-1e637b68-bea0-0043ce612782/debdev/debdev.vmx
Lock [type 10c00001 offset 143902720 v 29458, hb offset 3227648
gen 379, mode 1, owner 58e1fa80-df4c8bc2-bb87-005056d4f557 mtime 13631
num 0 gblnum 0 gblgen 0 gblbrk 0]
Addr <4, 265, 177>, gen 29281, links 1, type reg, flags 0, uid 0, gid 0, mode 100755
len 3040, nb 1 tbz 0, cow 0, newSinceEpoch 1, zla 2, bs 8192

Determine the world ID (on all ESXi Host), second column and kill all process.

~ # ps|grep yourVM|grep vmx
45168 45020 vmx-vcpu-0:yourVM - debdev SMT /bin/vmx
~ # kill -9 45020

And check if all process are terminated

~ # ps|grep yourVM

Check all ESXi Host for invalid VM configs.

~ # vim-cmd vmsvc/getallvms|grep ski
Skipping invalid VM '1527'

See if Id ‘1527’ is your vm

cat /etc/vmware/hostd/vmInventory.xml
~ # cat /etc/vmware/hostd/vmInventory.xml|grep -A 2 1527
    <objID>1527</objID>
    <vmxCfgPath>/vmfs/volumes/509bbbf5-1e637b68-bea0-0043ce612782/debdev/debdev.vmx</vmxCfgPath>

Then reload the VMs config on just one ESXi host which has the invalid VM in its Inventory

~ # vim-cmd vmsvc/reload 1527

Then all other ESXi Host should be updated and the VM appears back in the vSphere Inventory. You do not have to add it manually to inventory by browsing the datastore.

While powering vSphere may ask (Summary Tab in vSphere Client) you if the VM is moved or copied. Select “moved” because you don’t want to change the MAC Address of the virtual machine.

Michael

Advertisment to support michlstechblog.info

One thought on “VMware vSphere: Cannot register a virtual machine in inventory: A virtual machine or template having the same name is already registered”

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.