ESXi: reloading all virtual machines from their (potentially) vmx files
Posted by jpluimers on 2022/01/26
I had to reload all registered virtual machine configurations after replacing an NVMe adapter in one of my ESXi hosts (see the posts next week).
The below script is based on this series of April last year on listing, stopping, starting, hibernating and waking up VMs, especially vim-cmd-list-all-VMs.sh:
- VMware ESXi console: viewing all VMs, suspending and waking them up: part 1 on Busybox, sed and regular expressions (especially capture groups)
- VMware ESXi console: viewing all VMs, suspending and waking them up: part 2 on
vim-cmd vmsvccommands, especially the on the ones accepting avmidparameter - VMware ESXi console: viewing all VMs, suspending and waking them up: part 3 digging deeper into the various
vim-cmd vmsvc/power.*commands - VMware ESXi console: viewing all VMs, suspending and waking them up: part 4 on amending
vim-cmd vmsvc/getallvmswith information fromvim-cmd vmsvc/power.getstateandvim-cmd vmsvc/get.config - VMware ESXi console: viewing all VMs, suspending and waking them up: part 5 on applying the various
vim-cmd vmsvc/power.*commands on a list of relevant virtual machines
Here is the script vim-cmd-reload-all-VM-vmx-configurations.sh:
#!/bin/sh vmids=`vim-cmd vmsvc/getallvms | sed -n -E -e "s/^([[:digit:]]+)\s+((\S.+\S)?)\s+(\[\S+\])\s+(.+\.vmx)\s+(\S+)\s+(vmx-[[:digit:]]+)\s*?((\S.+)?)$/\1/p"` for vmid in ${vmids} ; do powerState=`vim-cmd vmsvc/power.getstate ${vmid} | sed '1d'` name=`vim-cmd vmsvc/get.config ${vmid} | sed -n -E -e '/\(vim.vm.ConfigInfo\) \{/,/files = \(vim.vm.FileInfo\) \{/ s/^ +name = "(.*)",.*?/\1/p'` vmPathName=`vim-cmd vmsvc/get.config ${vmid} | sed -n -E -e '/files = \(vim.vm.FileInfo\) \{/,/tools = \(vim.vm.ToolsConfigInfo\) \{/ s/^ +vmPathName = "(.*)",.*?/\1/p'` echo "Reloading vmx of VM with id ${vmid} which has power state ${powerState} (name = ${name}; vmPathName = ${vmPathName})." vim-cmd vmsvc/reload ${vmid} done exit 0
Note that the script can throw errors, for instance the below one:
# vim-cmd vmsvc/reload 27 (vmodl.fault.SystemError) { faultCause = (vmodl.MethodFault) null, faultMessage = , reason = "Invalid fault" msg = "Received SOAP response fault from []: reload vim.fault.InvalidState" }
This particular error means that the ESXi system itself is in an invalid state (as opposed to the virtual machine being an invalid state). In this case, it can be thrown if the ESXi system is in Maintenance Mode: in that case, it is not allowed to reload any .vmx virtual machine configurations (it only shows the configuration at the time that hostd got started).
There are two ways to solve this:
- The blunt way: restart the
hostdas this will re-read the.vmxfiles - The not so blunt way: bring the server out of maintenance mode, then rerun the
vim-cmd vmsvc/reloadcommand.
On the many places that can throw vim.fault.InvalidState
In this case, the reason for vim.fault.InvalidState was that the server was in maintenance mode. However, be aware that there are way more places that can throw vim.fault.InvalidState.
Via [Wayback/Archive.is] 1-day-SAP-custom/InvalidState.rst at master · bcstryker/1-day-SAP-custom and [Wayback/Archive.is] bcstryker/1-day-SAP-custom, I found [Wayback/Archive.is] InvalidState – vSphere Web Services API – VMware {code} that lists about 200 API calls for this seemingly simple fault:
Fault Description
An
InvalidStatefault is thrown if the operation failed due to the current state of the system.
For example, at [Wayback] Failed to deploy VM: vim.fault.InvalidState – VMware Technology Network VMTN the cause of vim.fault.InvalidState was deploying an .ova file over a slow WiFi connection.
On VMware services and their names
The VMware service names are very well explained in the [Wayback] what is difference between hostd, Vpxa and vpxd. – VMware Technology Network VMTN answer by [Wayback] About AndreTheGiant – VMware Technology Network VMTN
hostdis the daemon for direct VIC connection (when you use VIC to connect to your ESX).vpxis the original name of vCenter Center, so:vpxais the VC agent (ESX side)vpxdis the VC daemon (VC side)
Since ESXi 5.0, the VIC (VMware Infrastructure Client) got gradually replaced by the vSphere Web Client which is serviced by the hostd as well, see:
- [Wayback] Availability of the vSphere Clients for Linux systems (1006095)
- [Wayback] Article Detail: vSphere Client (HTML5) and vSphere Web Client 6.5 FAQ (2147929)
–jeroen






ESXi: on the console/ssh, when a moved VM pauses during power-on: show which VMs have messages waiting, then answer them « The Wiert Corner – irregular stream of stuff said
[…] ESXi: reloading all virtual machines from their (potentially) vmx files […]