I just replied to a topic on the VMTN forums and thought it might be useful to write it down here as well. (I thought I already did, but a search didn’t turn up anything.)
When a VM gets stuck during shutdown or isn’t responding anymore you can easily kill the VM. First option is the command line version of vCenter’s “shutdown vm”, first list all the VMs running on the host so you can copy and paste the <config> in to the next command. The command “vmware-cmd <config> stop trysoft” will try to initiate a soft shutdown first, in other words a shutdown via the Guest OS, if that doesn’t work it will do a power off. Now, as most of you probably already experienced, sometimes it’s impossible to shutdown the VMs in a normal way. This is where 2nd, 3rd and 4th option come in to place. Option two uses vm-support to kill the VM, use “-x” to list the VM id’s and kill it with “-X”. The third option uses vimsh, in this case we use vmware-vim-cmd, “vmsvc/getallvms” lists all VMs and the id’s and with “vmsvc/poweroff” you can specify the VM that needs to be powered off. The fourth option is the Linux/Unix way of doing it, find the process id of the VM via “ps -auxwww” and just kill it.
-
vmware-cmd -l
vmware-cmd <config> stop trysoft
-
vm-support -x
vm-support -X <vmid>
-
vmware-vim-cmd vmsvc/getallvms
vmware-vim-cmd vmsvc/poweroff <vm id>
-
ps -auxwww | grep <vm name>
kill <process id>
- if option three isn’t successful do the following:
kill -9 <process id>
As VMwareWolf points out, there’s an excellent KB article on this subject to be found here: http://kb.vmware.com/kb/1004340
I believe the Knowledge base article you were looking for that discusses this is at: http://kb.vmware.com/kb/1004340
Good stuff.
Back in the GSX Server days, I would use ‘vmware-cmd stop trysoft hard’ in my shutdown scripts. Is ‘hard’ implied now if ‘trysoft’ does not work?
I wasn’t aware of the -x option to grab the PID. My method is to use ESXTOP, and use ‘e’ to expand the PIDs of a particular VM. The method you demonstrate here is quicker.
Jas
Oh, and option 3 – who can remember all those silly little switches, except for Linux folks 🙂
I’ve had some success using vimsh where vmware-cmd will not work.
In vimsh:
vmsvc/getallvms (find the vmid you are looking for)
vmsvc/poweroff $vmid
Good article for reference, this issue does come up pretty often on the VMTN forums and I had just answered two questions last week regarding the same issue. Too bad there is not an equilv for ESXi, at least as far as I’m aware of.
@devnull – vmware-cmd is actually depreciated command, it works pretty well for the most part but there are times where it’ll just act up. I’m sure you could potentially get into the same issue as using vimsh or the vimsh wrapper. In either case, it’s good to know how to find the process and kill it.
Another post on the same. Nice to have the info in more hands: http://professionalvmware.com/2008/12/04/killing-a-stuck-or-hung-vm/
-Cody Bunch
http://professionalvmware.com
vmrun –help
or (eg)
vmrun -T ws stop /path/to/your/file/blah.vmx soft