Proxmox Wartungsmodus / Maintenance Mode - Diasable / Enable VMS at Start
Beschreibung
Man möchte den Server mehrmals neustarten, dann nervt es doch, wenn alle VMs/CTs mit starten.
Mit folgendem Script kann man das ein und auschalten
Installation des scripte
Auf den Server einloggen (sollte es ein Cluster sein, braucht das nur auf eine Node gepackt werden)
Nun eine Neue Datei erstellen
nano /root/save_boot_state.sh
Den Inhalt einfügen
#!/bin/bash
# boot-save-disable.sh
# Speichert alle onboot=1 VMs/CTs und deaktiviert sie
SAVEFILE="/root/boot-state.txt"
> "$SAVEFILE"
echo "=== Speichere Boot-Status ==="
for conf in /etc/pve/qemu-server/*.conf /etc/pve/lxc/*.conf; do
[ -f "$conf" ] || continue
if grep -q "^onboot: 1" "$conf"; then
id=$(basename "$conf" .conf)
type="vm"
[[ "$conf" == *"/lxc/"* ]] && type="ct"
echo "$type $id" >> "$SAVEFILE"
sed -i 's/^onboot: 1/onboot: 0/' "$conf"
echo " Deaktiviert: $type $id"
fi
done
echo ""
echo "Gespeichert in: $SAVEFILE"
echo "$(wc -l < "$SAVEFILE") Einträge"
Ausführbar machen
chmod +x /root/save_boot_state.sh
Wiederherstellung Script
nano /root/restore-boot-state.sh
Inhalt
#!/bin/bash
# boot-restore.sh
# Stellt onboot=1 für alle gespeicherten VMs/CTs wieder her
SAVEFILE="/root/boot-state.txt"
if [ ! -f "$SAVEFILE" ]; then
echo "Fehler: $SAVEFILE nicht gefunden!"
exit 1
fi
echo "=== Stelle Boot-Status wieder her ==="
while read -r type id; do
if [ "$type" = "vm" ]; then
conf="/etc/pve/qemu-server/${id}.conf"
else
conf="/etc/pve/lxc/${id}.conf"
fi
if [ -f "$conf" ]; then
if grep -q "^onboot:" "$conf"; then
sed -i 's/^onboot: 0/onboot: 1/' "$conf"
else
echo "onboot: 1" >> "$conf"
fi
echo " Aktiviert: $type $id"
else
echo " FEHLER: $conf nicht gefunden"
fi
done < "$SAVEFILE"
echo ""
echo "Fertig."
Ausführbar machen
chmod +x /root/restore_boot_state.sh
Status script
nano /root/status_boot_state.sh
Inhalt
#!/bin/bash
# boot-status.sh
# Zeigt aktuellen onboot-Status aller VMs/CTs
SAVEFILE="/root/boot-state.txt"
echo "=== Aktueller onboot-Status ==="
echo ""
printf "%-6s %-6s %-8s %s\n" "Typ" "ID" "onboot" "Name"
echo "-------------------------------------"
for conf in /etc/pve/qemu-server/*.conf /etc/pve/lxc/*.conf; do
[ -f "$conf" ] || continue
id=$(basename "$conf" .conf)
type="vm"; [[ "$conf" == *"/lxc/"* ]] && type="ct"
name=$(grep "^name:" "$conf" | awk '{print $2}')
[ -z "$name" ] && name=$(grep "^hostname:" "$conf" | awk '{print $2}')
onboot=$(grep "^onboot:" "$conf" | awk '{print $2}')
[ -z "$onboot" ] && onboot="0"
printf "%-6s %-6s %-8s %s\n" "$type" "$id" "$onboot" "${name:-}"
done
echo ""
if [ -f "$SAVEFILE" ]; then
echo "Gespeicherte Einträge in $SAVEFILE: $(wc -l < "$SAVEFILE")"
else
echo "Kein Savefile vorhanden ($SAVEFILE)"
fi
Ausführbar machen
chmod +x /root/status_boot_state.sh