Sometimes you may not be able to use vSphere to log in and power off/on a virtual machine which has gotten into a bad state, in my case my jump server for my lab environment was online and pinging OK however, it was no longer letting me RDP to it and needed a reboot.

Because the jump server is virtual, I would need access to vSphere to reboot the VM and investigate what’s going on using the console, the problem being the firewall protecting my lab does not permit HTTPS to vSphere from the AnyConnect VPN subnet, luckily I never disabled SSH access to the ESXi server – my saving grace!

Without SSH access enabled on the ESXi server, this process is not possible. This worked perfectly for me in VMware 6.0.0

SSH to the ESXi server, I use Putty as my SSH client. Once logged in, issue the command ‘esxcli vm process list‘ to list all running virtual machines:

[[email protected]:~] esxcli vm process list
EVE-NG
   World ID: 32378881
   Process ID: 0
   VMX Cartel ID: 32378880
   UUID: 56 4d 32 1a 1b 61 de bc-df ab 6f 9e e1 cb 32 30
   Display Name: EVE-NG
   Config File: /vmfs/volumes/5832c62c-05ed9c26-d51e-001b21c5b466/EVE-NG/EVE-NG.vmx

LAB-SRV01
   World ID: 50175258
   Process ID: 0
   VMX Cartel ID: 50174355
   UUID: 56 4d 2d cb 51 69 08 24-cd dd 4f 0c 7e 82 5e 86
   Display Name: LAB-SRV01
   Config File: /vmfs/volumes/5832c62c-05ed9c26-d51e-001b21c5b466/LAB-SRV01/LAB-SRV01.vmx

LAB-SRV01 is my lab server which I need to reboot, so I take note of the World ID to use during the next stage. I then issue the command to restart the virtual machine, referencing the correct World ID ‘esxcli vm process kill -t [soft,hard,force] -w <World ID>‘ (Soft is the most graceful method, hard performs an immediate shutdown and force should be used as a last resort!). After this command I re-list the running processes to confirm the VM has indeed been powered off.

[[email protected]:~] esxcli vm process kill -t soft -w 50175258
[[email protected]:~]
[[email protected]:~] esxcli vm process list
EVE-NG
   World ID: 32378881
   Process ID: 0
   VMX Cartel ID: 32378880
   UUID: 56 4d 32 1a 1b 61 de bc-df ab 6f 9e e1 cb 32 30
   Display Name: EVE-NG
   Config File: /vmfs/volumes/5832c62c-05ed9c26-d51e-001b21c5b466/EVE-NG/EVE-NG.vmx

To power the VM back on I will use the ‘vim-cmd vmsvc/getallvms‘ command to retrieve the VM ID, in this case my ID is 3, I then double check the power state of this VM by using the command ‘vim-cmd vmsvc/power.getstate <VM ID>‘:

[[email protected]:~] vim-cmd vmsvc/getallvms
Vmid      Name                       File                          Guest OS          Version   Annotation
18     EVE-NG       [datastore1] EVE-NG/EVE-NG.vmx           ubuntu64Guest           vmx-11
3      LAB-SRV01    [datastore1] LAB-SRV01/LAB-SRV01.vmx     windows8Server64Guest   vmx-11
[[email protected]:~] vim-cmd vmsvc/power.getstate 3
Retrieved runtime info
Powered off

I then issue ‘vim-cmd vmsvc/power.on <VM ID>‘ to turn the machine on:

[[email protected]:~] vim-cmd vmsvc/power.on 3
Powering on VM:

Waiting 5 minutes or so for the VM to fully boot, I was then able to RDP back onto the Windows server successfully.


0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *