Occasionally you may have need to kill a virtual machine that has become ‘stuck’.
I’ve see this a number of times when a VM has become stuck after sending it a shutdown request. When this happens, the VM will be in it’s ‘yellow’, ‘busy’ status in XenCenter, and will not respond to any requests.
The screenshot below shows a VM in this ‘stuck’ state in XenCenter.
The first step is to identify the host that the VM is running on, which is straight forward using XenCenter – the host in this example is xen1.vm.loc. Next, establish a CLI session to that host, using either SSH or, in this case, using the console tab in XenCenter:
Now, we need to find the ‘domain id’ for the virtual machine. To do so, run the following command (changing ‘XP1’ to the name of the stuck VM):
xe vm-list name-label=XP1 params=dom-id
The output shows that the dom-id for XP1 is ‘2’:
The next step is to confirm that the VM/Domain is running on the host, using the ‘list_domains’ command:
There are only a couple of domains here as I used my test lab for this, but if you have many VMs running and you want to confirm a domain-id is present in the output, use the grep command. For example, if the domain-id was 300:
list_domains | grep 300
The last step is the kill command itself, now that we have the dom-id and know that the VM is present. Run the following command:
/opt/xensource/debug/destroy_domain -domid
The Virtual machine should return to a powered off state, ready for use. As always, use caution when running console commands.