Finding the ESX/ESXi host on which a virtual machine is running
search cancel

Finding the ESX/ESXi host on which a virtual machine is running

book

Article ID: 310969

calendar_today

Updated On:

Products

VMware vCenter Server VMware vSphere ESXi

Issue/Introduction

This article provides the SQL statement to use when you want to find the ESX/ESXi host on which a virtual machine is running.
 
You may want to use this method when vCenter Server is down and you want to identify the host on which the virtual machine runs.


Environment

VMware ESXi 4.1.x Embedded
VMware vCenter Server 6.x
VMware vSphere ESXi 5.0
VMware ESXi 4.1.x Installable
VMware ESX 4.0.x
VMware vCenter Server 4.0.x
VMware vSphere ESXi 6.7
VMware vSphere ESXi 5.1
VMware ESX 4.1.x
VMware vCenter Server 4.1.x
VMware ESXi 4.0.x Installable
VMware ESXi 4.0.x Embedded
VMware vCenter Server 5.1.x
VMware vCenter Server 5.0.x
VMware vSphere ESXi 6.5

Resolution

To identify the host on which the virtual machine runs, use one of these methods:

Method 1

Query the vCenter Server database in MSSQL:
  1. Log in to to the Microsoft SQL 2005/2008 Server as an administrator.
  2. Open SQL Management Studio.
  3. Right-click the database that vCenter Server is using.
  4. Open a new query window and ensure that the vCenter Server database is selected.
  5. Run this SQL statement :

    SELECT vpxv_vms.vmid, vpxv_vms.NAME, vpxv_vms.hostid, vpxv_hosts.NAME
    FROM vpxv_vms
    JOIN vpxv_hosts on VPXV_VMS.HOSTID = VPXV_HOSTS.HOSTID
    WHERE (
    (vpxv_hosts.hostid = vpxv_vms.hostid)
    AND (vpxv_vms.NAME = 'virtual_machine_name')
    )


    This query returns the virtual machine ID, virtual machine name, host ID, and host name.

Method 2

Review the latest vmware.log file for the virtual machine:
  1. Open an SSH session to an ESX/ESXi host that has access to the shared storage (datastores) for the environment in which the virtual machine resides. For more information, see Connecting to an ESX host using a SSH client (1019852) or Using Tech Support Mode in ESXi 4.1 and ESXi 5.x (1017910).
  2. Find the working directory for the virtual machine using one of these commands:
    • grep -i <virtual_machine_name> /vmfs/volumes/*/*/vmware-*.log
    • find /vmfs/volumes/ -name *.vmx | less
       
  3. After locating the working directory of the virtual machine, check the latest vmware.log file and do the following steps on each Esxi host:
  •  Go to the working directory of the Virtual machine.
  • grep -i hostname vmware.log to determine the host on which the virtual machine is running
                On the host where the VM allocated and running, you see an entry similar to:
       2012-10-10T02:04:01.999Z| vmx| Hostname=name_of_host

       
On the other Esxi hosts, you see an entry similar to;
       Vmware.log: Device or resource busy 
      

 Note: The host where the VM is running lock the vmware.log file and VM_name.vmx file, trying to access these files from another Esxi host will return error with device busy that's The previous steps should be run one each host.



Additional Information

Using Tech Support Mode in ESXi 4.1, ESXi 5.x, and ESXi 6.x
Connecting to an ESX host using an SSH client
仮想マシンが実行されている ESX/ESXi ホストの検索
查找正在运行虚拟机的 ESX/ESXi 主机