Sometimes, the running virtual machine on the VMware ESXi host might freeze and not respond to the vSphere Client shutdown or restart command. In this article, we will find out how to force a VMWare virtual machine to power off when it becomes unresponsive (stuck).
When the virtual machine process on the ESXi server freezes, it stops responding to Reset
/Power Off
commands and any action results in an error such as:
- Another task is already in progress;
- The virtual machine might be performing concurrent operations. Actions: Complete the concurrent operation and retry the power-off operation; The virtual machine is in an invalid state;
- The attempted operation cannot be performed in the current state.
You can manually stop a stuck VM process on an ESXi host from the local ESXi shell or with PowerCLI commands without having to restart the server. Note that data loss in the guest operating system may occur if you force a VM shutdown (this is similar to the case when the power cord is disconnected from a physical computer).
- First, identify the ESXi host running a hung VM;
- Open vSphere Client and find the VM. The ESXi host name on which the VM is running is specified on the Summary tab in the Related Object -> Host section;
- Enable SSH on this ESXi host;
- Connect to ESXi using an SSH client (you can use the built-in Windows OpenSSH client);
- List the running VMs:
$ esxcli vm process list
- Copy the ID of the virtual machine you need (World ID);
- Use the following command to forcibly kill a stuck virtual machine process on the ESXi hypervisor:
$ esxcli vm process kill --type=[soft,hard,force] --world-id=WorldNumber
There are three options to kill the VM process on an ESXi host:
- Soft – the safest way to kill the VMX process (similar to
kill -SIGTERM
); - Hard – stop the VM process immediately (
kill -9
); - Force – used as a last resort if other options fail.
Try to perform a soft stop of the VM with the specified ID:
$ esxcli vm process kill --type=soft -w=20598249
The VM should shut down gracefully.
You can shut down a stuck virtual machine using PowerShell. This can be useful because when connecting to vCenter, there is no need to find the host where the VM is running and enable the SSH service on it. Connect to vCenter using PowerCLI and check if the VM is running:
Connect-VIServer <vCenter_or_ESXi_FQDN>
Get-VM “web1" | select name,PowerStates
Force stop the VM process with the command:
Stop-VM -kill "web1" -confirm:$false
The ESXTOP utility can also be used to stop an unresponsive VMWare virtual machine.
Run the esxtop
in an SSH session, then press c
to display CPU resources and SHIFT+V
to view virtual machine processes only.
Then press f
(select columns to display), c
(to display the LWID, Leader World ID), and then press ENTER.
Find your VM in the list and remember its LWID. Press k
(kill) and type the LWID identifier of the VM you want to force stop.
The final option for the hard shutdown of a virtual machine is the use of the kill tool. This method allows you to kill not only the VM but also any child processes.
Get the VM’s parent process ID:
ps | grep "web2"
Kill the VM process:
kill -9 24288474
The installed guest operating system will boot in recovery mode after a hard reset (the Windows Recovery Environment (WinRE) will start in the case of a Windows guest).
$ /etc/init.d/hostd restart
$ /etc/init.d/vpxa restart
1 comment
Great post! esxtop rocks!!
You can also use: esxcli or PowerCLI.
– esxcli:
esxcli vm process kill
– PowerCLI cmd-let:
Stop-VM with -Confirm:$false