added v3.8

This commit is contained in:
Adam.Tony
2025-10-22 12:59:32 +08:00
parent 7f77c5835e
commit 6c2664367c

View File

@@ -3,10 +3,10 @@
# Disk Health Check Script for Harvester OS # Disk Health Check Script for Harvester OS
# Checks SATA HDD, SATA SSD, SAS, NVMe, RAID controllers, and soft-raid # Checks SATA HDD, SATA SSD, SAS, NVMe, RAID controllers, and soft-raid
# Supports consumer and enterprise disk classification # Supports consumer and enterprise disk classification
# Created by Adam T. Lau
SCRIPT_NAME=$(basename "$0") SCRIPT_NAME=$(basename "$0")
VERSION="3.8" VERSION="3.8"
CREATOR="Adam T. Lau"
# Color codes # Color codes
RED=$(tput setaf 1) RED=$(tput setaf 1)
@@ -722,169 +722,148 @@ check_disk() {
else else
if [[ "$estimated_endurance" != "N/A" ]]; then if [[ "$estimated_endurance" != "N/A" ]]; then
echo "TBW Used: ${tbw_used} TB" echo "TBW Used: ${tbw_used} TB"
echo "TBW Endurance: ${estimated_endurance} TB" echo "TBW Endurance: ${estimated_endurance} TB (Minimum guaranteed - actual may be higher)"
local lifespan_info=$(estimate_ssd_lifespan "$power_on_hours" "$tbw_used" "$estimated_endurance" "$disk_type" "$percent_lifetime_used" "$has_write_data") local lifespan_info=$(estimate_ssd_lifespan "$power_on_hours" "$tbw_used" "$estimated_endurance" "$disk_type" "$percent_lifetime_used" "$has_write_data")
local lifespan_remaining=$(echo "$lifespan_info" | cut -d'|' -f1) local lifespan_percent=$(echo "$lifespan_info" | cut -d'|' -f1)
local tbw_remaining=$(echo "$lifespan_info" | cut -d'|' -f2) local tbw_remaining=$(echo "$lifespan_info" | cut -d'|' -f2)
local lifespan_status=$(echo "$lifespan_info" | cut -d'|' -f3) local wear_status=$(echo "$lifespan_info" | cut -d'|' -f3)
echo "TBW Remaining: $tbw_remaining" echo "TBW Remaining: $tbw_remaining"
echo "Lifespan: $lifespan_remaining ($lifespan_status)" echo "Lifespan: $lifespan_percent ($wear_status)"
else else
echo "Endurance: N/A" echo "TBW Used: ${tbw_used} TB"
echo "Lifespan: Unknown (Cannot estimate without usage data)"
fi fi
fi fi
if [[ "$disk_type" == "SAS SSD" ]]; then
echo "Realloc Sectors: $reallocated_sectors"
echo "Pending Sectors: $pending_sectors"
fi
else
print_color $YELLOW "Unknown disk type - limited information available"
echo "Realloc Sectors: $reallocated_sectors"
echo "Pending Sectors: $pending_sectors"
fi fi
echo "" echo ""
} }
# Function to detect and check all disks # Function to detect RAID controllers and disks
check_all_disks() { detect_raid_disks() {
print_color $GREEN "Disk Health Check Script v$VERSION" local controllers=("megaraid" "cciss" "areca" "3ware" "hpt" "aacraid" "auto")
print_color $BLUE "Creator: $CREATOR" local disks=()
# Check for direct disks first
for disk in /dev/sd[a-z] /dev/sd[a-z][a-z] /dev/nvme[0-9]n[0-9]; do
if [[ -b "$disk" ]]; then
disks+=("$disk:direct")
fi
done
# Check for RAID controllers
for controller in "${controllers[@]}"; do
for i in {0..31}; do
for base_disk in "/dev/sda" "/dev/sg$i" "/dev/sr$i"; do
if smartctl -d "$controller,$i" -i "$base_disk" >/dev/null 2>&1; then
disks+=("$base_disk:$controller,$i")
break
fi
done
done
done
echo "${disks[@]}"
}
# Main function
main() {
print_color $BLUE "Disk Health Check Script v$VERSION for Harvester OS"
print_color $BLUE "Created by Adam T. Lau"
print_color $BLUE "===================================================="
echo "" echo ""
# Check for RAID controllers first local disks=()
print_color $MAGENTA "Checking for RAID controllers..."
local raid_controllers=()
# Check for MegaRAID # Check for soft-raid first
if command_exists storcli64; then
raid_controllers+=("megaraid")
print_color $GREEN "Found MegaRAID controller (storcli64)"
elif command_exists storcli; then
raid_controllers+=("megaraid")
print_color $GREEN "Found MegaRAID controller (storcli)"
fi
# Check for 3ware
if command_exists tw_cli; then
raid_controllers+=("3ware")
print_color $GREEN "Found 3ware controller (tw_cli)"
fi
# Check for Areca
if command_exists cli64; then
raid_controllers+=("areca")
print_color $GREEN "Found Areca controller (cli64)"
fi
# Check for HP Smart Array
if command_exists hpssacli; then
raid_controllers+=("hpssacli")
print_color $GREEN "Found HP Smart Array controller (hpssacli)"
elif command_exists ssacli; then
raid_controllers+=("hpssacli")
print_color $GREEN "Found HP Smart Array controller (ssacli)"
fi
# Check for Adaptec
if command_exists arcconf; then
raid_controllers+=("adaptec")
print_color $GREEN "Found Adaptec controller (arcconf)"
fi
# Check software RAID
check_mdraid check_mdraid
# Check NVMe drives # If specific disk provided, check only that disk
print_color $MAGENTA "Checking NVMe drives..." if [[ $# -gt 0 ]]; then
local nvme_devices=() for disk in "$@"; do
for dev in /dev/nvme*; do if [[ -b "$disk" ]]; then
if [[ -b "$dev" && "$dev" =~ /dev/nvme[0-9]+n[0-9]+$ ]]; then disks+=("$disk:direct")
nvme_devices+=("$dev") else
fi print_color $RED "Error: $disk is not a valid block device"
done fi
if [[ ${#nvme_devices[@]} -gt 0 ]]; then
for nvme in "${nvme_devices[@]}"; do
check_disk "$nvme" ""
done done
else else
print_color $YELLOW "No NVMe drives found" # Auto-detect disks
print_color $CYAN "Auto-detecting disks..."
read -ra disks <<< "$(detect_raid_disks)"
fi fi
# Check direct SATA/SAS drives if [[ ${#disks[@]} -eq 0 ]]; then
print_color $MAGENTA "Checking direct SATA/SAS drives..." print_color $YELLOW "No disks found via auto-detection"
local direct_devices=() print_color $CYAN "Trying direct disk access..."
for dev in /dev/sd*; do for disk in /dev/sda /dev/sdb /dev/sdc /dev/nvme0n1; do
if [[ -b "$dev" && "$dev" =~ /dev/sd[a-z]+$ ]]; then if [[ -b "$disk" ]]; then
direct_devices+=("$dev") disks+=("$disk:direct")
fi fi
done
if [[ ${#direct_devices[@]} -gt 0 ]]; then
for dev in "${direct_devices[@]}"; do
check_disk "$dev" ""
done done
else
print_color $YELLOW "No direct SATA/SAS drives found"
fi fi
# Check drives behind RAID controllers if [[ ${#disks[@]} -eq 0 ]]; then
for controller_type in "${raid_controllers[@]}"; do print_color $RED "No disks found or accessible"
print_color $MAGENTA "Checking drives behind $controller_type controller..." echo "Try running as root or specifying disk paths manually"
exit 1
case $controller_type in fi
megaraid)
if command_exists storcli64; then print_color $GREEN "Found ${#disks[@]} disk(s) to check"
local enclosures=$(storcli64 /c0 show | grep -E "^[0-9]+" | awk '{print $1}') echo ""
for enc in $enclosures; do
local drives=$(storcli64 /c0/e$enc/sall show | grep -E "^[0-9]+" | awk '{print $1}') # Check each disk
for drive in $drives; do for disk_info in "${disks[@]}"; do
check_disk "/dev/sg$(echo $drive | cut -d':' -f1)" "megaraid,$drive" IFS=':' read -r disk controller <<< "$disk_info"
done check_disk "$disk" "$controller"
done
fi
;;
# Add other controller types as needed
esac
done done
# Footer note print_color $BLUE "Check completed!"
echo "" echo ""
print_color $CYAN "Note: SAS SSD TBW endurance is based on enterprise standards. Other SSD/NVMe TBW may vary depending on the specific model and manufacturer." print_color $YELLOW "Note: SAS SSDs often do not expose write statistics through SMART."
print_color $CYAN "Script by $CREATOR" print_color $YELLOW " TBW information may not be available for these drives."
print_color $YELLOW " SSD/NVMe TBW endurance may be higher depending on the specific model."
} }
# Help function # Usage information
show_help() { usage() {
echo "Usage: $SCRIPT_NAME [OPTIONS]" echo "Usage: $SCRIPT_NAME [DISK1 DISK2 ...]"
echo "Check disk health for various types of storage devices"
echo "" echo ""
echo "Options:" echo "If no disks specified, auto-detects all available disks and RAID arrays"
echo " -h, --help Show this help message"
echo " -v, --version Show version information"
echo "" echo ""
echo "Supported storage types:" echo "Examples:"
echo " - SATA HDD/SSD" echo " $SCRIPT_NAME # Check all auto-detected disks"
echo " - SAS HDD/SSD" echo " $SCRIPT_NAME /dev/sda # Check specific disk"
echo " - NVMe" echo " $SCRIPT_NAME /dev/nvme0n1 # Check specific NVMe disk"
echo " - RAID controllers (MegaRAID, 3ware, Areca, HP Smart Array, Adaptec)" echo " $SCRIPT_NAME /dev/sda /dev/nvme0n1 # Check multiple disks"
echo " - Software RAID (MDRAID)"
echo "" echo ""
echo "Requirements: smartmontools package must be installed" echo "Supported: SATA HDD/SSD, SAS HDD/SSD, NVMe, Hardware RAID, Software RAID"
echo "Created by Adam T. Lau"
} }
# Version function # Parse command line arguments
show_version() {
echo "$SCRIPT_NAME version $VERSION"
echo "Created by $CREATOR"
}
# Main script execution
case "${1:-}" in case "${1:-}" in
-h|--help) -h|--help)
show_help usage
exit 0 exit 0
;; ;;
-v|--version) -v|--version)
show_version echo "$SCRIPT_NAME version $VERSION"
echo "Created by Adam T. Lau"
exit 0 exit 0
;; ;;
*) *)
check_all_disks main "$@"
;; ;;
esac esac