Show NVMe drives with bay mappings in main table

NVMe drives mapped to m2-1, m2-2 slots now appear in the main drive
table with their bay position, instead of in a separate unmapped
section.

- Extended bay loop to include m2-* slots after numeric bays
- NVMe section now only shows truly unmapped NVMe drives
- Mapped NVMe drives show full SMART data like other drives

Fixes: #5

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-05 11:26:37 -05:00
parent ff1486dfe2
commit 16d9280a38

View File

@@ -460,8 +460,10 @@ for bay in "${!DRIVE_MAP[@]}"; do
fi fi
done done
# Sort drives by bay position # Sort drives by bay position (numeric bays first, then m2 slots)
for bay in $(printf '%s\n' "${!DRIVE_MAP[@]}" | grep -E '^[0-9]+$' | sort -n); do # Combine numeric bays (sorted numerically) with m2 slots (sorted alphanumerically)
all_bays=$(printf '%s\n' "${!DRIVE_MAP[@]}" | grep -E '^[0-9]+$' | sort -n; printf '%s\n' "${!DRIVE_MAP[@]}" | grep -E '^m2-' | sort)
for bay in $all_bays; do
device="${DRIVE_MAP[$bay]}" device="${DRIVE_MAP[$bay]}"
if [[ -n "$device" && "$device" != "EMPTY" && -b "/dev/$device" ]]; then if [[ -n "$device" && "$device" != "EMPTY" && -b "/dev/$device" ]]; then
size=$(lsblk -d -n -o SIZE "/dev/$device" 2>/dev/null) size=$(lsblk -d -n -o SIZE "/dev/$device" 2>/dev/null)
@@ -513,22 +515,33 @@ for bay in $(printf '%s\n' "${!DRIVE_MAP[@]}" | grep -E '^[0-9]+$' | sort -n); d
fi fi
done done
# NVMe drives # NVMe drives (only show unmapped ones - mapped NVMe drives appear in main table)
nvme_devices=$(lsblk -d -n -o NAME,SIZE | grep "^nvme" 2>/dev/null) nvme_devices=$(lsblk -d -n -o NAME,SIZE | grep "^nvme" 2>/dev/null)
if [ -n "$nvme_devices" ]; then if [[ -n "$nvme_devices" ]]; then
echo -e "\n=== NVMe Drives ===" # Filter out already-mapped NVMe devices
printf "%-15s %-10s %-10s %-40s %-25s\n" "DEVICE" "SIZE" "TYPE" "MODEL" "SERIAL" unmapped_nvme=""
echo "------------------------------------------------------------------------------------------------------" while read -r name size; do
echo "$nvme_devices" | while read -r name size; do if [[ -z "${DEVICE_TO_BAY[$name]:-}" ]]; then
device="/dev/$name" unmapped_nvme+="$name $size"$'\n'
# Get model and serial from smartctl for accuracy fi
smart_info=$(sudo smartctl -i "$device" 2>/dev/null) done <<< "$nvme_devices"
model=$(echo "$smart_info" | grep "Model Number" | cut -d: -f2 | xargs)
serial=$(echo "$smart_info" | grep "Serial Number" | cut -d: -f2 | xargs) if [[ -n "$unmapped_nvme" ]]; then
[[ -z "$model" ]] && model="-" printf "\n=== Unmapped NVMe Drives ===\n"
[[ -z "$serial" ]] && serial="-" printf "%-15s %-10s %-10s %-40s %-25s\n" "DEVICE" "SIZE" "TYPE" "MODEL" "SERIAL"
printf "%-15s %-10s %-10s %-40s %-25s\n" "$device" "$size" "NVMe" "$model" "$serial" echo "------------------------------------------------------------------------------------------------------"
done echo "$unmapped_nvme" | while read -r name size; do
[[ -z "$name" ]] && continue
device="/dev/$name"
# Get model and serial from smartctl for accuracy
smart_info="$(sudo smartctl -i "$device" 2>/dev/null)"
model="$(echo "$smart_info" | grep "Model Number" | cut -d: -f2 | xargs)"
serial="$(echo "$smart_info" | grep "Serial Number" | cut -d: -f2 | xargs)"
[[ -z "$model" ]] && model="-"
[[ -z "$serial" ]] && serial="-"
printf "%-15s %-10s %-10s %-40s %-25s\n" "$device" "$size" "NVMe" "$model" "$serial"
done
fi
fi fi
#------------------------------------------------------------------------------ #------------------------------------------------------------------------------