From db2a6e1e2062c716634e29b0338378d456a29751 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Wed, 3 Dec 2025 17:29:20 +0100 Subject: [PATCH] Update unifi-os-server-vm.sh --- vm/unifi-os-server-vm.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/vm/unifi-os-server-vm.sh b/vm/unifi-os-server-vm.sh index e93476650..f51377c06 100644 --- a/vm/unifi-os-server-vm.sh +++ b/vm/unifi-os-server-vm.sh @@ -87,11 +87,18 @@ function get_valid_nextid() { local try_id try_id=$(pvesh get /cluster/nextid) while true; do + # Check if VM config exists if [ -f "/etc/pve/qemu-server/${try_id}.conf" ] || [ -f "/etc/pve/lxc/${try_id}.conf" ]; then try_id=$((try_id + 1)) continue fi - if lvs --noheadings -o lv_name | grep -qE "(^|[-_])${try_id}($|[-_])"; then + # Check if VM or CT actually exists (running or stopped) + if qm status "$try_id" &>/dev/null || pct status "$try_id" &>/dev/null; then + try_id=$((try_id + 1)) + continue + fi + # Check if LVM volumes with this ID exist + if lvs --noheadings -o lv_name 2>/dev/null | grep -qE "(^|[-_])${try_id}($|[-_])"; then try_id=$((try_id + 1)) continue fi