From 2326520d176073f32d86ac22f40cd40f399328c6 Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Thu, 12 Feb 2026 20:06:02 +0100 Subject: [PATCH] Archlinux-VM: fix LVM/LVM-thin storage and improve error reporting | VM's add correct exit_code for analytics (#11842) * fix(archlinux-vm): fix LVM/LVM-thin storage and improve error reporting - Add catch-all (*) case for storage types (LVM, LVM-thin, zfspool) Previously only nfs/dir/cifs and btrfs were handled, leaving DISK_EXT, DISK_REF, and DISK_IMPORT unset on LVM/LVM-thin storage - Fix error_handler to send numeric exit_code to API instead of bash command text (which caused 'Unknown error' in telemetry) - Replace fragile pvesm alloc for EFI disk with Proxmox-managed :0,efitype=4m (consistent with docker-vm.sh) - Modernize disk import: auto-detect qm disk import vs qm importdisk, parse output to get correct disk reference instead of guessing names - Use --format flag (double dash) consistent with modern Proxmox API - Remove unused FORMAT variable (EFI type now always set correctly) - Remove fragile eval-based disk name construction * fix(vm): fix LVM/LVM-thin storage and error reporting for all VM scripts - Add catch-all (*) case to storage type detection in all VM scripts that were missing it (debian-vm, debian-13-vm, ubuntu2204/2404/2504, nextcloud-vm, owncloud-vm, opnsense-vm, pimox-haos-vm) - Add catch-all to mikrotik-routeros (had zfspool but not lvm/lvmthin) - Fix error_handler in ALL 14 VM scripts to send numeric exit_code to post_update_to_api instead of bash command text, which caused 'Unknown error' in telemetry because the API expects a number --- vm/archlinux-vm.sh | 43 ++++++++++++++++++++++++++--------------- vm/debian-13-vm.sh | 7 ++++++- vm/debian-vm.sh | 7 ++++++- vm/docker-vm.sh | 2 +- vm/haos-vm.sh | 2 +- vm/mikrotik-routeros.sh | 7 ++++++- vm/nextcloud-vm.sh | 7 ++++++- vm/openwrt-vm.sh | 2 +- vm/opnsense-vm.sh | 7 ++++++- vm/owncloud-vm.sh | 7 ++++++- vm/pimox-haos-vm.sh | 7 ++++++- vm/ubuntu2204-vm.sh | 7 ++++++- vm/ubuntu2404-vm.sh | 7 ++++++- vm/ubuntu2504-vm.sh | 7 ++++++- vm/umbrel-os-vm.sh | 2 +- 15 files changed, 91 insertions(+), 30 deletions(-) diff --git a/vm/archlinux-vm.sh b/vm/archlinux-vm.sh index 80a6f9927..14aa5ba0b 100644 --- a/vm/archlinux-vm.sh +++ b/vm/archlinux-vm.sh @@ -70,7 +70,7 @@ function error_handler() { local line_number="$1" local command="$2" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" - post_update_to_api "failed" "${command}" + post_update_to_api "failed" "${exit_code}" echo -e "\n$error_message\n" cleanup_vmid } @@ -203,7 +203,6 @@ function exit-script() { function default_settings() { VMID=$(get_valid_nextid) - FORMAT=",efitype=4m" MACHINE="" DISK_SIZE="4G" DISK_CACHE="" @@ -259,11 +258,9 @@ function advanced_settings() { 3>&1 1>&2 2>&3); then if [ "$MACH" = q35 ]; then echo -e "${CONTAINERTYPE}${BOLD}${DGN}Machine Type: ${BGN}$MACH${CL}" - FORMAT="" MACHINE=" -machine q35" else echo -e "${CONTAINERTYPE}${BOLD}${DGN}Machine Type: ${BGN}$MACH${CL}" - FORMAT=",efitype=4m" MACHINE="" fi else @@ -476,31 +473,45 @@ case $STORAGE_TYPE in nfs | dir | cifs) DISK_EXT=".qcow2" DISK_REF="$VMID/" - DISK_IMPORT="-format qcow2" + DISK_IMPORT="--format qcow2" THIN="" ;; btrfs) DISK_EXT=".raw" DISK_REF="$VMID/" - DISK_IMPORT="-format raw" - FORMAT=",efitype=4m" + DISK_IMPORT="--format raw" THIN="" ;; +*) + DISK_EXT="" + DISK_REF="" + DISK_IMPORT="--format raw" + ;; esac -for i in {0,1}; do - disk="DISK$i" - eval DISK"${i}"=vm-"${VMID}"-disk-"${i}"${DISK_EXT:-} - eval DISK"${i}"_REF="${STORAGE}":"${DISK_REF:-}"${!disk} -done msg_info "Creating a Arch Linux VM" qm create $VMID -agent 1${MACHINE} -tablet 0 -localtime 1 -bios ovmf${CPU_TYPE} -cores $CORE_COUNT -memory $RAM_SIZE \ -name $HN -tags community-script -net0 virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU -onboot 1 -ostype l26 -scsihw virtio-scsi-pci -pvesm alloc $STORAGE $VMID $DISK0 4M 1>&/dev/null -qm importdisk $VMID ${FILE} $STORAGE ${DISK_IMPORT:-} 1>&/dev/null + +if qm disk import --help >/dev/null 2>&1; then + IMPORT_CMD=(qm disk import) +else + IMPORT_CMD=(qm importdisk) +fi + +IMPORT_OUT="$("${IMPORT_CMD[@]}" "$VMID" "${FILE}" "$STORAGE" ${DISK_IMPORT:-} 2>&1 || true)" +DISK_REF_IMPORTED="$(printf '%s\n' "$IMPORT_OUT" | sed -n "s/.*successfully imported disk '\([^']\+\)'.*/\1/p" | tr -d "\r\"'")" +[[ -z "$DISK_REF_IMPORTED" ]] && DISK_REF_IMPORTED="$(pvesm list "$STORAGE" | awk -v id="$VMID" '$5 ~ ("vm-"id"-disk-") {print $1":"$5}' | sort | tail -n1)" +[[ -z "$DISK_REF_IMPORTED" ]] && { + msg_error "Unable to determine imported disk reference." + echo "$IMPORT_OUT" + exit 1 +} +msg_ok "Imported disk (${CL}${BL}${DISK_REF_IMPORTED}${CL})" + qm set $VMID \ - -efidisk0 ${DISK0_REF}${FORMAT} \ - -scsi0 ${DISK1_REF},${DISK_CACHE}${THIN}size=${DISK_SIZE} \ + -efidisk0 ${STORAGE}:0,efitype=4m \ + -scsi0 ${DISK_REF_IMPORTED},${DISK_CACHE}${THIN%,} \ -ide2 ${STORAGE}:cloudinit \ -boot order=scsi0 \ -serial0 socket >/dev/null diff --git a/vm/debian-13-vm.sh b/vm/debian-13-vm.sh index af036768e..fcf0f7978 100644 --- a/vm/debian-13-vm.sh +++ b/vm/debian-13-vm.sh @@ -70,7 +70,7 @@ function error_handler() { local line_number="$1" local command="$2" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" - post_update_to_api "failed" "${command}" + post_update_to_api "failed" "${exit_code}" echo -e "\n$error_message\n" cleanup_vmid } @@ -560,6 +560,11 @@ btrfs) FORMAT=",efitype=4m" THIN="" ;; +*) + DISK_EXT="" + DISK_REF="" + DISK_IMPORT="-format raw" + ;; esac for i in {0,1}; do disk="DISK$i" diff --git a/vm/debian-vm.sh b/vm/debian-vm.sh index 7692b8c3d..1af726b3d 100644 --- a/vm/debian-vm.sh +++ b/vm/debian-vm.sh @@ -70,7 +70,7 @@ function error_handler() { local line_number="$1" local command="$2" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" - post_update_to_api "failed" "${command}" + post_update_to_api "failed" "${exit_code}" echo -e "\n$error_message\n" cleanup_vmid } @@ -501,6 +501,11 @@ btrfs) FORMAT=",efitype=4m" THIN="" ;; +*) + DISK_EXT="" + DISK_REF="" + DISK_IMPORT="-format raw" + ;; esac for i in {0,1}; do disk="DISK$i" diff --git a/vm/docker-vm.sh b/vm/docker-vm.sh index f45da27ad..b4de65d94 100644 --- a/vm/docker-vm.sh +++ b/vm/docker-vm.sh @@ -45,7 +45,7 @@ function error_handler() { local line_number="$1" local command="$2" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" - post_update_to_api "failed" "${command}" + post_update_to_api "failed" "${exit_code}" echo -e "\n$error_message\n" cleanup_vmid } diff --git a/vm/haos-vm.sh b/vm/haos-vm.sh index f82b5940a..ab490b002 100644 --- a/vm/haos-vm.sh +++ b/vm/haos-vm.sh @@ -74,7 +74,7 @@ function error_handler() { local line_number="$1" local command="$2" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" - post_update_to_api "failed" "${command}" + post_update_to_api "failed" "${exit_code}" echo -e "\n$error_message\n" cleanup_vmid } diff --git a/vm/mikrotik-routeros.sh b/vm/mikrotik-routeros.sh index 0f000a84c..6ea0c868b 100644 --- a/vm/mikrotik-routeros.sh +++ b/vm/mikrotik-routeros.sh @@ -71,7 +71,7 @@ function error_handler() { local line_number="$1" local command="$2" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" - post_update_to_api "failed" "${command}" + post_update_to_api "failed" "${exit_code}" echo -e "\n$error_message\n" cleanup_vmid } @@ -566,6 +566,11 @@ zfspool) DISK_REF="" DISK_IMPORT="-format raw" ;; +*) + DISK_EXT="" + DISK_REF="" + DISK_IMPORT="-format raw" + ;; esac DISK_VAR="vm-${VMID}-disk-0${DISK_EXT:-}" diff --git a/vm/nextcloud-vm.sh b/vm/nextcloud-vm.sh index 130b8148f..960322d5d 100644 --- a/vm/nextcloud-vm.sh +++ b/vm/nextcloud-vm.sh @@ -70,7 +70,7 @@ function error_handler() { local line_number="$1" local command="$2" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" - post_update_to_api "failed" "${command}" + post_update_to_api "failed" "${exit_code}" echo -e "\n$error_message\n" cleanup_vmid } @@ -487,6 +487,11 @@ btrfs) FORMAT=",efitype=4m" THIN="" ;; +*) + DISK_EXT="" + DISK_REF="" + DISK_IMPORT="-format raw" + ;; esac for i in {0,1,2}; do disk="DISK$i" diff --git a/vm/openwrt-vm.sh b/vm/openwrt-vm.sh index 00e85c5d7..f14708f86 100644 --- a/vm/openwrt-vm.sh +++ b/vm/openwrt-vm.sh @@ -74,7 +74,7 @@ function error_handler() { local exit_code="$?" local line_number="$1" local command="$2" - post_update_to_api "failed" "$command" + post_update_to_api "failed" "$exit_code" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" echo -e "\n$error_message\n" cleanup_vmid diff --git a/vm/opnsense-vm.sh b/vm/opnsense-vm.sh index bc5acbf2d..9d7eac26a 100644 --- a/vm/opnsense-vm.sh +++ b/vm/opnsense-vm.sh @@ -48,7 +48,7 @@ function error_handler() { local exit_code="$?" local line_number="$1" local command="$2" - post_update_to_api "failed" "$command" + post_update_to_api "failed" "$exit_code" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" echo -e "\n$error_message\n" cleanup_vmid @@ -619,6 +619,11 @@ btrfs) FORMAT=",efitype=4m" THIN="" ;; +*) + DISK_EXT="" + DISK_REF="" + DISK_IMPORT="-format raw" + ;; esac for i in {0,1}; do disk="DISK$i" diff --git a/vm/owncloud-vm.sh b/vm/owncloud-vm.sh index bff0d7f88..8cfd668f8 100644 --- a/vm/owncloud-vm.sh +++ b/vm/owncloud-vm.sh @@ -71,7 +71,7 @@ function error_handler() { local line_number="$1" local command="$2" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" - post_update_to_api "failed" "${command}" + post_update_to_api "failed" "${exit_code}" echo -e "\n$error_message\n" cleanup_vmid } @@ -500,6 +500,11 @@ btrfs) FORMAT=",efitype=4m" THIN="" ;; +*) + DISK_EXT="" + DISK_REF="" + DISK_IMPORT="-format raw" + ;; esac for i in {0,1,2}; do disk="DISK$i" diff --git a/vm/pimox-haos-vm.sh b/vm/pimox-haos-vm.sh index 07e1740a1..e234ecc96 100644 --- a/vm/pimox-haos-vm.sh +++ b/vm/pimox-haos-vm.sh @@ -79,7 +79,7 @@ function error_handler() { local line_number="$1" local command="$2" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" - post_update_to_api "failed" "${command}" + post_update_to_api "failed" "${exit_code}" echo -e "\n$error_message\n" cleanup_vmid } @@ -402,6 +402,11 @@ nfs | dir) DISK_REF="$VMID/" DISK_IMPORT="-format qcow2" ;; +*) + DISK_EXT="" + DISK_REF="" + DISK_IMPORT="-format raw" + ;; esac for i in {0,1}; do disk="DISK$i" diff --git a/vm/ubuntu2204-vm.sh b/vm/ubuntu2204-vm.sh index 55a4dee7d..910691104 100644 --- a/vm/ubuntu2204-vm.sh +++ b/vm/ubuntu2204-vm.sh @@ -66,7 +66,7 @@ function error_handler() { local exit_code="$?" local line_number="$1" local command="$2" - post_update_to_api "failed" "$command" + post_update_to_api "failed" "$exit_code" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" echo -e "\n$error_message\n" cleanup_vmid @@ -482,6 +482,11 @@ btrfs) FORMAT=",efitype=4m" THIN="" ;; +*) + DISK_EXT="" + DISK_REF="" + DISK_IMPORT="-format raw" + ;; esac for i in {0,1}; do disk="DISK$i" diff --git a/vm/ubuntu2404-vm.sh b/vm/ubuntu2404-vm.sh index 565718d88..d2c503458 100644 --- a/vm/ubuntu2404-vm.sh +++ b/vm/ubuntu2404-vm.sh @@ -69,7 +69,7 @@ function error_handler() { local exit_code="$?" local line_number="$1" local command="$2" - post_update_to_api "failed" "$command" + post_update_to_api "failed" "$exit_code" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" echo -e "\n$error_message\n" cleanup_vmid @@ -484,6 +484,11 @@ btrfs) FORMAT=",efitype=4m" THIN="" ;; +*) + DISK_EXT="" + DISK_REF="" + DISK_IMPORT="-format raw" + ;; esac for i in {0,1}; do disk="DISK$i" diff --git a/vm/ubuntu2504-vm.sh b/vm/ubuntu2504-vm.sh index 5e6d3a800..7ba4da312 100644 --- a/vm/ubuntu2504-vm.sh +++ b/vm/ubuntu2504-vm.sh @@ -68,7 +68,7 @@ function error_handler() { local exit_code="$?" local line_number="$1" local command="$2" - post_update_to_api "failed" "$command" + post_update_to_api "failed" "$exit_code" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" echo -e "\n$error_message\n" cleanup_vmid @@ -483,6 +483,11 @@ btrfs) FORMAT=",efitype=4m" THIN="" ;; +*) + DISK_EXT="" + DISK_REF="" + DISK_IMPORT="-format raw" + ;; esac for i in {0,1}; do disk="DISK$i" diff --git a/vm/umbrel-os-vm.sh b/vm/umbrel-os-vm.sh index 02a5bb439..25ef06ed2 100644 --- a/vm/umbrel-os-vm.sh +++ b/vm/umbrel-os-vm.sh @@ -69,7 +69,7 @@ function error_handler() { local line_number="$1" local command="$2" local error_message="${RD}[ERROR]${CL} in line ${RD}$line_number${CL}: exit code ${RD}$exit_code${CL}: while executing command ${YW}$command${CL}" - post_update_to_api "failed" "${command}" + post_update_to_api "failed" "${exit_code}" echo -e "\n$error_message\n" cleanup_vmid }