Thursday 6 December 2012

Shutdown VM's via command line (esxcli)

There comes a time when you use vSphere client to shut down a virtual machine and you get no response or you need to power down some VM's and vCenter is unavailable. When this happens you would normally console to the ESXi host and start using command line to shut down. Using "esxcli" instead of "vim-cmd" now is so much easier in vSphere 5

1) SSH or get to the console of your ESXi host. I am assuming you know which host the VM currently resides. At the prompt type in "esxcli vm process list".


Running this command will list all the current running VM's as shown below. See if the one you wish to shut down is listed and make a note of the "world id"


2) Now for the command, to kill off the VM you would type in:
 "esxcli vm process kill --type={soft,hard,force} --world-id={world id}"

The kill type "soft" means trying to shut down the OS like how you would normally shut down an OS, "hard" means shutting down the OS without giving a chance for the applications to shut down, "force" means it doesn't care what state it is in, it will force the VM to switch off just like pushing a power switch.

So with the example I have above I would type in "esxcli vm process kill --type=soft --world-id=9741765"


3) Once the command has run successfully it will return you back to the prompt. Type in:
 "esxcli vm process list"

See if the VM that you are trying to power off is still listed. If you have selected kill type "soft" then it may take a few moments before it will  be powered off so run the command "esxcli vm process list" a few times. If after a few times or you waited long enough and feel the VM is not doing anything then run the command in step 2 again but using hard type instead


No comments:

Post a Comment

New Azure KMS IP and domain Addresses for activation

For Windows virtual machines deployed into Azure using marketplace images you may have created rules in your NSG or firewalls to allow the s...