The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,804 other followers

ESXi: editing /etc/vmware/hostd/vmInventory.xml to fix the datastore UUID for unavailable VMs

Posted by jpluimers on 2021/12/23

In case I ever need this on ESXi:

  1. Put first ESX host into maintenance mode, or disable automatic DRS.
  2. Migrate functioning VMs onto other hosts.
  3. SSH into ESX service console.
  4. cd /vmfs/volumes
  5. ls -l:
    [root@esx1 volumes]# ls -l
    drwxrwxrwt    1 root        1260 Nov 27 11:58 474c4a74-b4cc8c53-6e29-000423c3e840
    drwxrwxrwt    1 root         980 Nov 27 08:49 474c4aa2-772bdc66-e441-000423c3e840
    drwxrwxrwt    1 root        1260 Nov 27 11:58 474c955b-527b5a13-1417-000423c3e840
    lrwxr-xr-x    1 root          35 Nov 29 13:36 snap-00000002-VMFS11 -> 474c955b-527b5a13-1417-000423c3e840
    lrwxr-xr-x    1 root          35 Nov 29 13:36 VMFS11 -> 474c4a74-b4cc8c53-6e29-000423c3e840
    lrwxr-xr-x    1 root          35 Nov 29 13:36 VMFS13 -> 474c4aa2-772bdc66-e441-000423c3e840
  6. Note (or copy) the new UUID(s) of the datastore(s) on which the inaccessible VMs live.  You may need to look in the VMFS themselves to be sure which VMs live where.
  7. cd /etc/vmware/hostd
  8. cp vmInventory.xml vmInventory.xml-save
  9. Edit vmInventory.xml and change the UUID for the inaccessible VMs to the correct UUID for their datastores.  (If unsure which VMs are in which datastore, look in each datastore to ensure you have the right UUID for each VM).
  10. Save vmInventory.xml and exit the editor.
  11. To make ESX re-read vmInventory.xml:
    [root@esx1 hostd]# service mgmt-vmware restart
    Stopping VMware ESX Server Management services:
    VMware ESX Server Host Agent Watchdog [ OK ]
    VMware ESX Server Host Agent [ OK ]
    Starting VMware ESX Server Management services:
    VMware ESX Server Host Agent (background) [ OK ]
    Availability report startup (background) [ OK ]
  12. Verify all VMs are properly accessible.
  13. Bring the ESX host out of maintenance mode and/or return DRS to original settings.

Sample vmInventory.xml file with UUID paths for VMs in an NFS and a VMFS datastore:

[root@esx1 hostd]# more vmInventory.xml
<ConfigRoot>
  <ConfigEntry id="0006">
    <objID>112</objID>
    <vmxCfgPath>/vmfs/volumes/9f801592-14465f39/WinNFS8/WinNFS8.vmx</vmxCfgPath>
  </ConfigEntry>
  <ConfigEntry id="0027">
    <objID>608</objID>
    <vmxCfgPath>/vmfs/volumes/46e5a3bf-2d233fa0-1546-0014220f1381/houwin2003sp2-8/houwin2003sp2-8.vmx</vmxCfgPath>
  </ConfigEntry>
</ConfigRoot>

Note about restarting the VMware Management stack through service mgmt-vmware restart:

little addition: You can also use the dcui via ssh.

Just enter dcui in your ssh session. Then you can restart the management agents like on the local console.

To quit hit Ctrl+C

Running VMs won’t be affected

  • For troubleshooting ESXi connectivity issue, restart the management agents on your ESXi host. Warning: If LACP is configured on the vSAN network, do not restart[Wayback] Restarting the Management agents in ESXi (1003490)

    Restart Management agents in ESXi Using Direct Console User Interface (DCUI):

    1. Connect to the console of your ESXi host.
    2. Press F2 to customize the system.
    3. Log in as root.
    4. Use the Up/Down arrows to navigate to Troubleshooting Options > Restart Management Agents.
    5. Press Enter.
    6. Press F11 to restart the services.
    7. When the service restarts, press Enter.
    8. Press Esc to log out.

    Note: You can also restart services using the Host Client. In Host Client, select Host >> Manage >> Services and select the service to restart.

    Restart Management agents in ESXi Using ESXi Shell or Secure Shell (SSH):
    1. Log in to ESXi Shell or SSH as root.For Enabling ESXi Shell or SSH, see Using ESXi Shell in ESXi 5.x and 6.x (2004746).
    2. Restart the ESXi host daemon and vCenter Agent services using these commands:/etc/init.d/hostd restart/etc/init.d/vpxa restart
    Alternatively:
    • To reset the management network on a specific VMkernel interface, by default vmk0, run the command:esxcli network ip interface set -e false -i vmk0; esxcli network ip interface set -e true -i vmk0Note: Using a semicolon (;) between the two commands ensures the VMkernel interface is disabled and then re-enabled in succession. If the management interface is not running on vmk0, change the above command according to the VMkernel interface used.
    • To restart all management agents on the host, run the command:services.sh restart
    Caution:
    • If LACP is enabled and configured, do not restart management services using services.sh command. Instead restart independent services using the /etc/init.d/module restart command.
    • If the issue is not resolved, and you are restarting all the services that are a part of the services.sh script, take a downtime before proceeding to the script.
    • If NSX is configured in the environment, do not run the /sbin/services.sh restart command because this will restart all services on the ESXi host. If you need to restart the management agents on the ESXi host, restart vpxa, host.d, and fdm individually. If you also need to run the /sbin/services.sh restart command because restarting each management agent does not work, then migrate all the VMs off the ESXi host and put the host in maintenance mode if possible.
    • If you are unsure that NSX for vSphere is installed on an ESXi host, run this command to verify:
    esxcli software vib list –rebooting-image | grep esx-*
    Look for the following VIBs to determine if NSX is installed on the ESX host:
    vsip-esx
    esx-vxlan
    • If using shared graphics in a View environment (VGPU, vDGA, vSGA), do not use services.sh. This will shut down the xorg service which is responsible for graphics at the guest OS level. By ripping the graphics out of the guest OS you will in term cause the crash of your VDI workload using the shared graphics. Ensure you are using shared graphics to only restart hostd, and vpxa if you are not in maintenance mode.

When editing the inventory fails

If all else fails and all VMs need to be re-registered: [Wayback] Virtual machines appear as unknown in Inventory on host and invalid in vCenter Server (1031605)

 Symptoms
  • vSphere Client direct to host show virtual machine(s) as unknown.
  • The vSphere Client connected to vCenter Server shows virtual machine(s) as invalid.
  • No errors on storage or on vmkwarning.
  • All the virtual machines on the host are functional and responding.
 Resolution
To resolve this issue:
For ESXi 3.5, 4.x, 5.x, 6.x
  1. Log in to the VMware ESX/ESXi host as the root user. For more information on VMware ESXi 4.1 and ESXi 5.x Technical Support Mode, see Using Tech Support Mode in ESXi 4.1 and ESXi 5.x (1017910)
  2. To list all running virtual machines and their corresponding VMIDs, run these commands:vim-cmd vmsvc/getallvms
    cd /etc/vmware/hostd/
  3. Make a copy of vmInventory.xml file by running this command:cp vmInventory.xml vmInventory.xml.bak
  4. Stop the vpxa and hostd services by running these commands:/etc/init.d/vpxa stop
    /etc/init.d/hostd stop
  5. Rename the vmInventory.xml file by running this command:Note: This action unregisters all virtual machines from the host.mv vmInventory.xml vmInventory_xml.bak
  6. Start the vpxa and hostd services by running these commands:/etc/init.d/vpxa start
    /etc/init.d/hostd start
  7. Log in to vSphere Client and verify that the virtual machine Inventory is now displayed as blank.
  8. Use this command to register every virtual machine back to Inventory on the host:vim-cmd solo/registervm full_path_of_VMXFor Example: vim-cmd solo/registervm /vmfs/volumes/datastore_name/VM_directory/VM_name.vmx

–jeroen

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: