Update scripts for disk

This commit is contained in:
MacRimi 2025-04-08 18:00:35 +02:00
parent 84912fcaac
commit aed76879b1
3 changed files with 49 additions and 23 deletions

View File

@ -175,15 +175,19 @@ while read -r DISK; do
USED_BY="" USED_BY=""
REAL_PATH=$(readlink -f "$DISK") REAL_PATH=$(readlink -f "$DISK")
CONFIG_DATA=$(cat /etc/pve/qemu-server/*.conf /etc/pve/lxc/*.conf 2>/dev/null) CONFIG_DATA=$(cat /etc/pve/qemu-server/*.conf /etc/pve/lxc/*.conf 2>/dev/null)
for SYMLINK in /dev/disk/by-id/*; do if grep -Fq "$REAL_PATH" <<< "$CONFIG_DATA"; then
if [[ "$(readlink -f "$SYMLINK")" == "$REAL_PATH" ]]; then USED_BY="$(translate "In use")"
if grep -Fq "$SYMLINK" <<< "$CONFIG_DATA"; then else
USED_BY="$(translate "in use ct or vm")" for SYMLINK in /dev/disk/by-id/*; do
break if [[ "$(readlink -f "$SYMLINK")" == "$REAL_PATH" ]]; then
if grep -Fq "$SYMLINK" <<< "$CONFIG_DATA"; then
USED_BY="$(translate "In use")"
break
fi
fi fi
fi done
done fi
@ -215,7 +219,7 @@ while read -r DISK; do
[[ "$IS_LVM" == true ]] && LABEL+=" ⚠ LVM" [[ "$IS_LVM" == true ]] && LABEL+=" ⚠ LVM"
[[ "$IS_ZFS" == true ]] && LABEL+=" ⚠ ZFS" [[ "$IS_ZFS" == true ]] && LABEL+=" ⚠ ZFS"
DESCRIPTION=$(printf "%-24s %10s%s" "$MODEL" "$SIZE" "$LABEL") DESCRIPTION=$(printf "%-30s %10s%s" "$MODEL" "$SIZE" "$LABEL")
FREE_DISKS+=("$DISK" "$DESCRIPTION" "OFF") FREE_DISKS+=("$DISK" "$DESCRIPTION" "OFF")
fi fi
done < <(lsblk -dn -e 7,11 -o PATH) done < <(lsblk -dn -e 7,11 -o PATH)
@ -311,7 +315,7 @@ for DISK in $SELECTED; do
done < <(pct list | awk 'NR>1 {print $1, $2}') done < <(pct list | awk 'NR>1 {print $1, $2}')
if [ -n "$RUNNING_VMS" ] || [ -n "$RUNNING_CTS" ]; then if [ -n "$RUNNING_VMS" ] || [ -n "$RUNNING_CTS" ]; then
ERROR_MESSAGES+="$(translate "The disk") $DISK_INFO $(translate "is in use by the following running VM(s) or CT(s):")\\n$RUNNING_VMS$RUNNING_CTS\\n\\n" ERROR_MESSAGES+="$(translate "The disk") $DISK_INFO $(translate "is currently in use by the following running VM(s) or CT(s):")\\n$RUNNING_VMS$RUNNING_CTS\\n\\n$(translate "You cannot add this disk while the VM or CT is running.")\\n$(translate "Please shut it down first and run this script again to add the disk.")\\n\\n"
continue continue
fi fi

View File

@ -221,15 +221,19 @@ while read -r DISK; do
USED_BY="" USED_BY=""
REAL_PATH=$(readlink -f "$DISK") REAL_PATH=$(readlink -f "$DISK")
CONFIG_DATA=$(cat /etc/pve/qemu-server/*.conf /etc/pve/lxc/*.conf 2>/dev/null) CONFIG_DATA=$(cat /etc/pve/qemu-server/*.conf /etc/pve/lxc/*.conf 2>/dev/null)
for SYMLINK in /dev/disk/by-id/*; do if grep -Fq "$REAL_PATH" <<< "$CONFIG_DATA"; then
if [[ "$(readlink -f "$SYMLINK")" == "$REAL_PATH" ]]; then USED_BY="$(translate "In use")"
if grep -Fq "$SYMLINK" <<< "$CONFIG_DATA"; then else
USED_BY="$(translate "in use ct or vm")" for SYMLINK in /dev/disk/by-id/*; do
break if [[ "$(readlink -f "$SYMLINK")" == "$REAL_PATH" ]]; then
if grep -Fq "$SYMLINK" <<< "$CONFIG_DATA"; then
USED_BY="$(translate "In use")"
break
fi
fi fi
fi done
done fi
@ -257,7 +261,7 @@ while read -r DISK; do
[[ "$IS_LVM" == true ]] && LABEL+=" ⚠ LVM" [[ "$IS_LVM" == true ]] && LABEL+=" ⚠ LVM"
[[ "$IS_ZFS" == true ]] && LABEL+=" ⚠ ZFS" [[ "$IS_ZFS" == true ]] && LABEL+=" ⚠ ZFS"
DESCRIPTION=$(printf "%-24s %10s%s" "$MODEL" "$SIZE" "$LABEL") DESCRIPTION=$(printf "%-30s %10s%s" "$MODEL" "$SIZE" "$LABEL")
FREE_DISKS+=("$DISK" "$DESCRIPTION" "OFF") FREE_DISKS+=("$DISK" "$DESCRIPTION" "OFF")
fi fi
done < <(lsblk -dn -e 7,11 -o PATH) done < <(lsblk -dn -e 7,11 -o PATH)
@ -399,7 +403,7 @@ for DISK in $SELECTED; do
if [[ "$CURRENT_FS" == "ext4" || "$CURRENT_FS" == "xfs" || "$CURRENT_FS" == "btrfs" ]]; then if [[ "$CURRENT_FS" == "ext4" || "$CURRENT_FS" == "xfs" || "$CURRENT_FS" == "btrfs" ]]; then
SKIP_FORMAT=true SKIP_FORMAT=true
PARTITION="$DISK" PARTITION="$DISK"
msg_ok "$(translate "Detected filesystem") $CURRENT_FS $(translate "directly on disk") $DISK. $(translate "Proceeding without partition.")" msg_ok "$(translate "Detected filesystem") $CURRENT_FS $(translate "directly on disk") $DISK.)"
else else
whiptail --title "$(translate "No Valid Partitions")" --yesno "$(translate "The disk has no partitions and no valid filesystem. Do you want to create a new partition and format it?")" 10 70 whiptail --title "$(translate "No Valid Partitions")" --yesno "$(translate "The disk has no partitions and no valid filesystem. Do you want to create a new partition and format it?")" 10 70

View File

@ -546,6 +546,23 @@ function select_passthrough_disk() {
IS_MOUNTED=true IS_MOUNTED=true
fi fi
USED_BY=""
REAL_PATH=$(readlink -f "$DISK")
CONFIG_DATA=$(cat /etc/pve/qemu-server/*.conf /etc/pve/lxc/*.conf 2>/dev/null)
if grep -Fq "$REAL_PATH" <<< "$CONFIG_DATA"; then
USED_BY="$(translate "In use")"
else
for SYMLINK in /dev/disk/by-id/*; do
if [[ "$(readlink -f "$SYMLINK")" == "$REAL_PATH" ]]; then
if grep -Fq "$SYMLINK" <<< "$CONFIG_DATA"; then
USED_BY="$(translate "In use")"
break
fi
fi
done
fi
if $IS_RAID && grep -q "$DISK" <<< "$(cat /proc/mdstat)" && grep -q "active raid" /proc/mdstat; then if $IS_RAID && grep -q "$DISK" <<< "$(cat /proc/mdstat)" && grep -q "active raid" /proc/mdstat; then
SHOW_DISK=false SHOW_DISK=false
fi fi
@ -555,9 +572,10 @@ function select_passthrough_disk() {
fi fi
if $SHOW_DISK; then if $SHOW_DISK; then
[[ "$IS_RAID" == true ]] && LABEL+=" ⚠ with partitions" [[ -n "$USED_BY" ]] && LABEL+=" [$USED_BY]"
[[ "$IS_LVM" == true ]] && LABEL+=" ⚠ LVM" [[ "$IS_RAID" == true ]] && LABEL+=" ⚠ RAID"
[[ "$IS_ZFS" == true ]] && LABEL+=" ⚠ ZFS" [[ "$IS_LVM" == true ]] && LABEL+=" ⚠ LVM"
[[ "$IS_ZFS" == true ]] && LABEL+=" ⚠ ZFS"
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")
fi fi