Update disk-passthrough_ct.sh

This commit is contained in:
MacRimi 2025-04-08 10:45:14 +02:00 committed by GitHub
parent 54ee8ef7c7
commit eda5a34058
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -218,19 +218,18 @@ while read -r DISK; do
fi fi
USED_BY="" USED_BY=""
while read -r ID NAME STATUS; do REAL_PATH=$(readlink -f "$DISK")
if [[ "$ID" =~ ^[0-9]+$ ]]; then CONFIG_DATA=$(cat /etc/pve/qemu-server/*.conf /etc/pve/lxc/*.conf 2>/dev/null)
if qm config "$ID" 2>/dev/null | grep -q "$DISK"; then
USED_BY="vm $ID" for SYMLINK in /dev/disk/by-id/*; do
break if [[ "$(readlink -f "$SYMLINK")" == "$REAL_PATH" ]]; then
elif pct config "$ID" 2>/dev/null | grep -q "$DISK"; then if grep -Fq "$SYMLINK" <<< "$CONFIG_DATA"; then
USED_BY="ct $ID" USED_BY="$(translate "in use ct or vm")"
break break
fi fi
fi fi
done < <(pvesh get /nodes/$(hostname)/qemu --output-format=json | jq -r '.[] | "\(.vmid) \(.name) running"' ; \ done
pvesh get /nodes/$(hostname)/lxc --output-format=json | jq -r '.[] | "\(.vmid) \(.name) running"')
@ -253,10 +252,10 @@ while read -r DISK; do
fi fi
if $SHOW_DISK; then if $SHOW_DISK; then
[[ "$IS_RAID" == true ]] && LABEL+=" ⚠ with partitions" [[ -n "$USED_BY" ]] && LABEL+=" [$USED_BY]"
[[ "$IS_RAID" == true ]] && LABEL+=" ⚠ RAID"
[[ "$IS_LVM" == true ]] && LABEL+=" ⚠ LVM" [[ "$IS_LVM" == true ]] && LABEL+=" ⚠ LVM"
[[ "$IS_ZFS" == true ]] && LABEL+=" ⚠ ZFS" [[ "$IS_ZFS" == true ]] && LABEL+=" ⚠ ZFS"
[[ -n "$USED_BY" ]] && LABEL+=" [$USED_BY]"
DESCRIPTION=$(printf "%-30s %10s%s" "$MODEL" "$SIZE" "$LABEL") DESCRIPTION=$(printf "%-30s %10s%s" "$MODEL" "$SIZE" "$LABEL")
FREE_DISKS+=("$DISK" "$DESCRIPTION" "OFF") FREE_DISKS+=("$DISK" "$DESCRIPTION" "OFF")
@ -525,4 +524,4 @@ if [ -n "$ERROR_MESSAGES" ]; then
whiptail --title "$(translate "Warnings and Errors")" --msgbox "$ERROR_MESSAGES" 16 70 whiptail --title "$(translate "Warnings and Errors")" --msgbox "$ERROR_MESSAGES" 16 70
fi fi
exit 0 exit 0