ESXi: editing /etc/vmware/hostd/vmInventory.xml to fix the datastore UUID for unavailable VMs part 2
Posted by jpluimers on 2022/02/01
I started my post ESXi: editing /etc/vmware/hostd/vmInventory.xml to fix the datastore UUID for unavailable VMs with
In case I ever need this on ESXi: Insights into the VMware inventory files (
vmAutoStart.xml
andvmInventory.xml
on ESXi;inventory.vmls
on VMware Workstation/Player)
Since almost all of my blog is about things I bumped into in real life, this post was a preparation because I kind of expected this to indeed happen, and it did.
Below are the screenshots and steps I took. Of course it is an N=1 experience, so your situation might differ, but I tried to be thorough and not miss any steps.
- First of all, you always have to ensure that none of the virtual machines are running on the ESXi host (ideally they should be powered off, but hibernated/suspended usually works as well). For this, I use
vim-cmd-hibernate-running-VMs.sh
orvim-cmd-power-off-powered-on-VMs.sh
from VMware ESXi console: viewing all VMs, suspending and waking them up: part 5 . - Then the ESXi host needs to be in maintenance mode (I use
esxcli-maintenanceMode-show.sh
andesxcli-maintenanceMode-enter.sh
andesxcli-maintenanceMode-exit.sh
from VMware ESXi 6 and 7: checking and setting/clearing maintenance mode from the console) - After taking two of the NVMe devices out (they were about to fail, I had back-ups), the inventory looked like this:
ESXi VMs after taking out failing NVMe SSDs
None of the virtual machines are available, and the full path of their .vmx file is visible instead of the virtual machine names that normally are obtained from the .vmx files.
- Since I knew the old and new vmfs UUIDs, I could use
vi
to edit/etc/vmware/hostd/vmInventory.xml
and perform these search and replace operations (and save+quit using:wq
):
:%s/5ad4aeea-6954841c-470e-0cc47aaa9742/6097a4eb-6c6e4c76-46d3-0cc47aaa9742/g :%s:5ad4af1b-f3ae285c-e0f4-0cc47aaa9742:6097a4eb-6c6e4c76-46d3-0cc47aaa9742/base/archiveteam:g :%s:/archiveteam-warrior-v3-20171013 instance 2/:/archiveteam-warrior-v3-20171013.instance-2/:g
I always have to lookup the
vi
search/replace phrases, as they are similar, but not identical to thesed
syntax, so I write this blog post that I use to find them back: Source: On learningvi
/vim
. - Now I could restart the services, which gave an error (note the
connot
spelling mistake):
# /sbin/services.sh restart Errors: Invalid operation requested: This ruleset is required and connot be disabled
- I inspected the below log files, and there were no anomalies: they all looked similar to what happens after a server reboot (which takes quite some time because of the thorough boot checks of the BIOS SuperMicro on the motherboard and HBA adapters):
/var/log/hostd.log
,/var/log/jumpstart-stdout.log
,/var/log/vmkernel.log
,/var/log/vpxa.log
(log files via [Wayback] Services Failing on ESXi 5.5 Host – Can’t Restart Services | [H]ard|Forum – search for “normalish” and “stableish” – and [Wayback] services.sh restart problem – This ruleset is requ… – VMware Technology Network VMTN). - After fixing
/etc/vmware/hostd/vmInventory.xml
and restarting the services:
ESXi VMs after editing
/etc/vmware/hostd/vmInventory.xml
to correct vmfs UUIDs and paths.The (blurred) virtual machine names are back as well as power states, disk sizes, operating systems, etc.
- I wasn’t done yet, because since the
.vmx
files themselves contain absolute references to at least.iso
and.vswp
files, so I needed to fix that by first getting a list of.vmx
files from thevmInventory.xml
file:
# sed -n -E -e "s/^ +<vmxCfgPath>(.+)<\/vmxCfgPath>$/\1/p" /etc/vmware/hostd/vmInventory.xml
- This will get you the files; usually they are in entries like
ide0:0.fileName
,sata0:0.fileName
andsched.swap.derivedName
:
# sed -n -E -e "s/^ +<vmxCfgPath>(.+)<\/vmxCfgPath>$/\1/p" /etc/vmware/hostd/vmInventory.xml | xargs -n 1 -I {} grep "vmfs" {}
- Appending
| sed -n -E -e "s#^.+? = (\"/.*\")#\1#p" | sort | uniq | xargs ls -Alh
will list the files in unique sorted order:
# sed -n -E -e "s/^ +<vmxCfgPath>(.+)<\/vmxCfgPath>$/\1/p" /etc/vmware/hostd/vmInventory.xml | xargs -n 1 -I {} grep "vmfs" {} | sed -n -E -e "s#^.+? = (\"/.*\")#\1#p" | sort | uniq | xargs ls -Alh
Note that the backslash
\
escaped double quotes"
are inside the parenthesis()
because filenames can contain spaces. - For me the list was like this:
Valid and invalid files referenced from
.vmx
files - This gave me the volume UUIDs that I had to replace, of which the first bunch until
x
were all.iso
disk images referenced by disconnected optical devices and the last ones available.iso
disk images. The remaining ones corresponded to replace operations I already had done on thevmInventory.xml
file, so I could repeat that exercise, open each file invi
and repeat the search operations. This is the statement to open each.vmx
file invi
:
# sed -n -E -e "s/^ +<vmxCfgPath>(.+)<\/vmxCfgPath>$/\1/p" /etc/vmware/hostd/vmInventory.xml | xargs -n 1 -I {} grep -l "vmfs" {} | xargs -n 1 -I [] echo "vi \"[]\""
Note that the double quotes
"
because filenames can contain spaces, and the same search and replace operations I used on the/etc/vmware/hostd/vmInventory.xml
file::%s/5ad4aeea-6954841c-470e-0cc47aaa9742/6097a4eb-6c6e4c76-46d3-0cc47aaa9742/g :%s:5ad4af1b-f3ae285c-e0f4-0cc47aaa9742:6097a4eb-6c6e4c76-46d3-0cc47aaa9742/base/archiveteam:g :%s:/archiveteam-warrior-v3-20171013 instance 2/:/archiveteam-warrior-v3-20171013.instance-2/:g
- Now the ESXi host needs to get out of maintenance mode (I use
esxcli-maintenanceMode-show.sh
andesxcli-maintenanceMode-exit.sh
from VMware ESXi 6 and 7: checking and setting/clearing maintenance mode from the console) immediately followed by the next step (otherwise someone else could start a virtual machine with the old.vmx
information) - Reloading all the
vmx
configurations can be done withvim-cmd-reload-all-VM-vmx-configurations.sh
as I described yesterday in Source: ESXi: reloading all virtual machines from their (potentially) vmx files. - Note that when powering on virtual machines, you need to answer a question like this for each virtual machine:
This virtual machine might have been moved or copied. In order to configure certain management and networking features, VMware ESX needs to know if this virtual machine was moved or copied. If you don’t know, answer “I Copied It”.
- I Moved It
- I Copied It
One more thing
A final note: I need to check out if .vswp
files need to be there at all, as my ESXi servers have plenty of physical memory in order not to swap out to disk. More on that in a future blog post.
Leave a Reply