kvm hard kill

Änderungsstand: 2024-06-03

Das Nervigste, was mir passiert ist, war, als sich eine VM einfach nicht ausschalten lassen wollte. Deshalb den kompletten Knoten neu zu starten, finde ich nicht innovativ. Deshalb hier die Lösung, die ohne Knoten-Neustart auskommt:

In der Proxmox-Shell:

nano kill_kvm.sh

Folgendes hinzufügen (Stand: 2024-06):

#!/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"

Strg-x, y, Enter

chmod +x kill_kvm.sh

Um nun eine VM Hart zu Beenden, folgenden Befehl eingeben (119 ist die ID meiner VM):

./kill_kvm.sh 119

Die VM wird beendet.

root@pve:~# ./kill_kvm.sh 119
Killing KVM process (PID: 8850416) for VMID 119
Process killed successfully
root@pve:~#

Quelle:

Github: Rhodiym/kill_kvm.sh

https://gist.github.com/Rhodiym/85b6bf10818ffd8f6fa168318184d6af

Erstelle eine Website wie diese mit WordPress.com
Jetzt starten