Managing ESXi 5 VM from the command line

       239 words, 2 minutes

I only have one physical machine and my vSphere client is installed on a Windows XP virtual machine. If, for some reason, that VM is not usable, I need a way to manage my VM from the ESXi. Here’s a few reminders on commands to use to manage VM from the VMware ESXi v5 command line.

Every command is used from the ESXi itself, via a remote SSH connexion. Those could also be run from a distant machine where the vSphere Command-Line Interface (vCLI) has been installed.

List the actual running machines:

# esxcli vm process list | grep "^[^ ]"

List the registered virtual machines:

# vim-cmd vmsvc/getallvms
Vmid         Name                              File                              Guest OS          Version                               Annotation                             
(...)
11     vCenter (win2k8)   [SATA_local] Win2K8/Win2K8.vmx                   windows7Server64Guest   vmx-08                                                                       
31     OpenBSD            [SATA_local] OpenBSD/OpenBSD.vmx                 otherGuest              vmx-08                                                                       
(...)

Get the state of a particular machine, using its VMid:

  # vim-cmd vmsvc/power.getstate ##
  Retrieved runtime info
  Powered on

Shutdown the virtual machine “nicely”, using its VMid:

  # vim-cmd vmsvc/power.shutdown ##

Power the machine off, using its VMid:

  # vim-cmd vmsvc/power.off ##

Start the virtual machine, using its VMid:

  # vim-cmd vmsvc/power.on ##

If the CLI commands don’t work, one can stop a VM using the default system tools:

  # ps | grep vmx-mks
  3542 3538 vmx-mks:WinXP            /bin/vmx
  3959 3953 vmx-mks:Windows 7 x64    /bin/vmx
  3969 3964 vmx-mks:Ubuntu           /bin/vmx
  3978 3973 vmx-mks:vCenter (win2k8) /bin/vmx
  3986 3981 vmx-mks:OpenBSD          /bin/vmx
  
  # kill ##       (use the second column from the `ps` command)