Last active
June 14, 2024 18:02
-
-
Save Rhodiym/85b6bf10818ffd8f6fa168318184d6af to your computer and use it in GitHub Desktop.
Resolving Proxmox VE - Kill VM - Shutdown Bug
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
############################################################################################ | |
# MIT License | |
# | |
# Copyright (c) 2024 Caleb Rhody | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
# | |
############################################################################################ | |
# Resolving Proxmox VE Shutdown Bug | |
# If you're encountering issues with shutting down a Proxmox Virtual Machine (VM) | |
# due to the "QEMU Guest Agent" being enabled, this script provides a quick solution. | |
# The problem is documented in [this Proxmox forum post](https://forum.proxmox.com/threads/stop-vm-impossible.101736) | |
# and [bug report](https://bugzilla.proxmox.com/show_bug.cgi?id=4474). | |
# | |
# Special Thanks to "oguz - Proxmox Retired Staff" for the solution provided in | |
# [this forum post](https://forum.proxmox.com/threads/stop-vm-impossible.101736/post-438745). | |
# | |
# Usage: | |
# 1. Download the script: [kill_kvm.sh] (https://gist.github.com/Rhodiym) | |
# 2. Make the script executable: `chmod +x kill_kvm.sh` | |
# 3. Run the script with the VMID you want to shut down: `./kill_kvm.sh <VMID>` | |
# | |
# Example: | |
# ./kill_kvm.sh 106 | |
# | |
# This script finds and kills the KVM process associated with the specified VMID, | |
# addressing the shutdown bug caused by enabling "QEMU Guest Agent" for your VM. | |
# | |
# [PATCH] (https://lists.proxmox.com/pipermail/pve-devel/2023-January/055587.html) | |
############################################################################################ | |
# Check if VMID is provided as an argument | |
if [ -z "$1" ]; then | |
echo "Usage: $0 <VMID>" | |
exit 1 | |
fi | |
VMID=$1 | |
# Find the process ID (PID) of the KVM process for the specified VMID | |
KVM_PID=$(ps aux | grep "/usr/bin/kvm.*-id $VMID" | grep -v grep | awk '{print $2}') | |
# Check if a process ID was found | |
if [ -z "$KVM_PID" ]; then | |
echo "No KVM process found for VMID $VMID" | |
exit 1 | |
fi | |
# Kill the KVM process using SIGKILL (kill -9) | |
echo "Killing KVM process (PID: $KVM_PID) for VMID $VMID" | |
kill -9 "$KVM_PID" | |
echo "Process killed successfully" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment