Kill a Proxmox VM that won't quit with a one-liner using the pve node's command prompt

I was using the handy information at Proxmox can’t stop VM – How we fix it! (bobcares.com) for a while. They have a two-line approach which does the job, but displays the (very) long command line for starting a proxmox VM on the screen while doing so. To me, facing a wall of text while searching for the process ID means it takes an extra microsecond or two to perform. So here's the one-liner approach:

# kill -9 `ps aux | grep "/usr/bin/kvm -id 104" | grep splash | awk '{print $2}'`

Simply replace the 104 above with the VMID you want to end, and the VM will die immediately.

Here's the quiet two line approach, as it is oddly one microsecond easier to hit the up-arrow twice and edit the "bye=104" line, than to locate and edit the VMID within the longer one-liner before pressing Enter:

# bye=104
# kill -9 `ps aux | grep "/usr/bin/kvm -id ${bye}" | grep splash | awk '{print $2}'`

I use this when I'm experimenting with multiple deployments of a VM that doesn't have qemu-guest-agent installed and thus does not die when politely requested, but needs to die repeatedly (how gruesome this sounds while writing) before the experiment is concluded.

[Update] Uh... warning on using the 2-line version. The shell for proxmox apparently starts a new session each time you bring it up, which means the environment variable "bye" disappears. I didn't know this, and I up-arrowed, then re-ran the kill line, but ${bye} was empty, and I ended up killing every VM! That was so unexpected, I restarted the whole server just to make sure things were copacetic.

So be careful. I think I'll use the one-liner version going forward.

Add a comment

HTML code is displayed as text and web addresses are automatically converted.

Page top