Add serial numbers to drive details output

Changes:
- Added SERIAL column to SATA/SAS drive details table
- Added SERIAL column to NVMe drive details table
- Updated get_drive_smart_info() to extract and return serial numbers
- Widened output format to accommodate serial numbers
- NVMe serials now display correctly from nvme list output

This makes it much easier to match drives to their physical locations
by comparing visible serial numbers on drive labels with the output.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-06 16:16:04 -05:00
parent be541cba97
commit d5c784033e

View File

@@ -175,8 +175,9 @@ get_drive_smart_info() {
local type=$(echo "$smart_info" | grep "Rotation Rate" | grep -q "Solid State" && echo "SSD" || echo "HDD")
local health=$(echo "$smart_info" | grep "SMART overall-health" | grep -q "PASSED" && echo "✓" || echo "✗")
local model=$(echo "$smart_info" | grep "Device Model\|Model Number" | cut -d: -f2 | xargs)
local serial=$(echo "$smart_info" | grep "Serial Number" | awk '{print $3}')
echo "$type|$temp°C|$health|$model"
echo "$type|$temp°C|$health|$model|$serial"
}
#------------------------------------------------------------------------------
@@ -211,16 +212,16 @@ esac
#------------------------------------------------------------------------------
echo -e "\n=== Drive Details with SMART Status ==="
printf "%-15s %-10s %-8s %-8s %-8s %-30s\n" "DEVICE" "SIZE" "TYPE" "TEMP" "HEALTH" "MODEL"
echo "--------------------------------------------------------------------------------"
printf "%-15s %-10s %-8s %-8s %-8s %-30s %-20s\n" "DEVICE" "SIZE" "TYPE" "TEMP" "HEALTH" "MODEL" "SERIAL"
echo "----------------------------------------------------------------------------------------------------------------------------"
# SATA/SAS drives
lsblk -d -o NAME | grep -v "nvme" | grep -v "rbd" | grep -v "loop" | grep -v "NAME" | while read device; do
if [ -b "/dev/$device" ]; then
size=$(lsblk -d -n -o SIZE "/dev/$device" 2>/dev/null)
smart_info=$(get_drive_smart_info "$device")
IFS='|' read -r type temp health model <<< "$smart_info"
printf "%-15s %-10s %-8s %-8s %-8s %-30s\n" "/dev/$device" "$size" "$type" "$temp" "$health" "$model"
IFS='|' read -r type temp health model serial <<< "$smart_info"
printf "%-15s %-10s %-8s %-8s %-8s %-30s %-20s\n" "/dev/$device" "$size" "$type" "$temp" "$health" "$model" "$serial"
fi
done
@@ -229,9 +230,9 @@ if command -v nvme >/dev/null 2>&1; then
nvme_drives=$(sudo nvme list 2>/dev/null | grep "^/dev")
if [ -n "$nvme_drives" ]; then
echo -e "\n=== NVMe Drives ==="
printf "%-15s %-10s %-10s %-40s\n" "DEVICE" "SIZE" "TYPE" "MODEL"
echo "--------------------------------------------------------------------------------"
echo "$nvme_drives" | awk '{printf "%-15s %-10s %-10s %-40s\n", $1, $6, "NVMe", $3}'
printf "%-15s %-10s %-10s %-40s %-20s\n" "DEVICE" "SIZE" "TYPE" "MODEL" "SERIAL"
echo "----------------------------------------------------------------------------------------------------------------------------"
echo "$nvme_drives" | awk '{printf "%-15s %-10s %-10s %-40s %-20s\n", $1, $6, "NVMe", $3, $2}'
fi
fi