Tags

,

Sometimes you have to boot your VMs from the command line. This can happen when you have a power failure, or possibly as part of detailed start-up/shutdown procedures. No matter the reason getting familiar with, and documenting this option is a good best practice. In fact, creating a few dummy VMs to learn this process is even better.

Perform the following at either the ESXi console or via SSH Putty/xterm session.

1) To power on a VM from the command line, find the inventory ID of the VM. The first column is the VMID.
> vim-cmd vmsvc/getallvms |grep <name of your vm>

Or, if you just want to list them all, use getallvms.
> vim-cmd vmsvc/getallvms

Vmid  Name         File                                                Guest     Version
5       vcentersql  [vms] vcentersql/vcentersql.vmx   winSrv64Guest  vmx-09
8       labdc01      [vms] labdc01/labdc01.vmx           winSrv64Guest  vmx-09
10     splunk         [vms] splunk/splunk.vmx              winSrv64Guest  vmx-09
11     Kali105        [vms] Kali105/Kali105.vmx           deb664Guest   vmx-08
12     nessus        [vms] nessus/nessus.vmx            deb664Guest   vmx-08

2) Check the power state of the virtual machine you need to boot. In this case, I need to boot the Domain Controller first so I choose the Vmid 8 from the list above
> vim-cmd vmsvc/power.getstate 8
Retrieved runtime info
Powered off

3) Now that you have the Vmid and know the current state, boot the VM.
> vim-cmd vmsvc/power.on 8
Powering on VM

4) Check the process. Note that this command will only list your started and running VMs.
> esxcli vm process list
labdc01
World ID: 52680
Process ID: 0
VMX Cartel ID: 52669
UUID: 42 27 d6 f3 45 20 22 52-cb d2 b7 e1 c4 13 1a f4
Display Name: labdc01
Config File: /vmfs/volumes/9faff676-f7876623/labdc01/labdc01.vmx

4) Verify that the VM is up. Also verify on the VM Console or if Windows, RDP into the VM. Note that if your vCenter is not up, use the vSphere Client to login directly to the ESXi Host to check the VM console.
> vim-cmd vmsvc/power.getstate 8
Retrieved runtime info
Powered on

For reference, if you need to power off, reset or reboot a VM from the command line:

1) Get the Vmid from the output of getallvms.
> vim-cmd vmsvc/getallvms

2) Using the Vmid of the above command for the VM you want to control,  choose the command below based on the action you want to take (reboot, shutdown or reset).
> vim-cmd vmsvc/power.reboot <vmid>
> vim-cmd vmsvc/power.reset <vmid>
> vim-cmd vmsvc/power.shutdown <vmid>