/dev/disk/by-path/ mapping

This commit is contained in:
2025-03-01 13:00:53 -05:00
parent 9d29708b64
commit ab30387714

View File

@ -51,6 +51,39 @@ get_physical_mapping() {
done
}
declare -A DRIVE_MAPPINGS=(
["medium2"]="
pci-0000:0c:00.0-ata-3:5
pci-0000:0c:00.0-ata-4:6
pci-0000:0c:00.0-ata-1:4
pci-0000:0c:00.0-ata-2:5
"
["large1"]=""
["medium1"]=""
)
build_drive_map() {
local host=$(hostname)
local drive_map=()
# Get mapping for current host
local mapping=${DRIVE_MAPPINGS[$host]}
if [[ -n "$mapping" ]]; then
while read -r path_slot; do
[[ -z "$path_slot" ]] && continue
local path=${path_slot%:*}
local slot=${path_slot#*:}
if [[ -L "/dev/disk/by-path/$path" ]]; then
local drive=$(readlink -f "/dev/disk/by-path/$path" | sed 's/.*\///')
drive_map+=("${slot}:${drive}")
fi
done <<< "$mapping"
fi
}
# Define the ASCII art maps
large1='''
┌─────────────────────────────────────────────────────────────┐
@ -133,16 +166,16 @@ generate_medium2_layout() {
# Map drives to bays dynamically
for bay in {1..10}; do
local drive_path=$(ls -l /dev/disk/by-path/pci-0000:0c:00.0-ata-$bay 2>/dev/null)
if [ -n "$drive_path" ]; then
local drive=$(echo "$drive_path" | awk -F'/' '{print $NF}')
printf "│ │ %-6s │" "$drive"
else
printf "│ │ EMPTY │"
fi
local drive="EMPTY"
for mapping in "${drive_map[@]}"; do
if [[ $mapping == "$bay:"* ]]; then
drive="${mapping#*:}"
break
fi
done
printf "│ │ %-6s │" "$drive"
done
printf " │\n"
printf "│ └────────┘└────────┘└────────┘└────────┘└────────┘└────────┘└────────┘└────────┘└────────┘└────────┘ │\n"
printf "└──────────────────────────────────────────────────────────────┘\n"
}