added v3.8
This commit is contained in:
@@ -3,10 +3,10 @@
|
||||
# Disk Health Check Script for Harvester OS
|
||||
# Checks SATA HDD, SATA SSD, SAS, NVMe, RAID controllers, and soft-raid
|
||||
# Supports consumer and enterprise disk classification
|
||||
# Created by Adam T. Lau
|
||||
|
||||
SCRIPT_NAME=$(basename "$0")
|
||||
VERSION="3.8"
|
||||
CREATOR="Adam T. Lau"
|
||||
|
||||
# Color codes
|
||||
RED=$(tput setaf 1)
|
||||
@@ -722,169 +722,148 @@ check_disk() {
|
||||
else
|
||||
if [[ "$estimated_endurance" != "N/A" ]]; then
|
||||
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_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 lifespan_status=$(echo "$lifespan_info" | cut -d'|' -f3)
|
||||
local wear_status=$(echo "$lifespan_info" | cut -d'|' -f3)
|
||||
|
||||
echo "TBW Remaining: $tbw_remaining"
|
||||
echo "Lifespan: $lifespan_remaining ($lifespan_status)"
|
||||
echo "Lifespan: $lifespan_percent ($wear_status)"
|
||||
else
|
||||
echo "Endurance: N/A"
|
||||
echo "TBW Used: ${tbw_used} TB"
|
||||
echo "Lifespan: Unknown (Cannot estimate without usage data)"
|
||||
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
|
||||
|
||||
echo ""
|
||||
}
|
||||
|
||||
# Function to detect and check all disks
|
||||
check_all_disks() {
|
||||
print_color $GREEN "Disk Health Check Script v$VERSION"
|
||||
print_color $BLUE "Creator: $CREATOR"
|
||||
# Function to detect RAID controllers and disks
|
||||
detect_raid_disks() {
|
||||
local controllers=("megaraid" "cciss" "areca" "3ware" "hpt" "aacraid" "auto")
|
||||
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 ""
|
||||
|
||||
# Check for RAID controllers first
|
||||
print_color $MAGENTA "Checking for RAID controllers..."
|
||||
local raid_controllers=()
|
||||
local disks=()
|
||||
|
||||
# Check for MegaRAID
|
||||
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 for soft-raid first
|
||||
check_mdraid
|
||||
|
||||
# Check NVMe drives
|
||||
print_color $MAGENTA "Checking NVMe drives..."
|
||||
local nvme_devices=()
|
||||
for dev in /dev/nvme*; do
|
||||
if [[ -b "$dev" && "$dev" =~ /dev/nvme[0-9]+n[0-9]+$ ]]; then
|
||||
nvme_devices+=("$dev")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#nvme_devices[@]} -gt 0 ]]; then
|
||||
for nvme in "${nvme_devices[@]}"; do
|
||||
check_disk "$nvme" ""
|
||||
# If specific disk provided, check only that disk
|
||||
if [[ $# -gt 0 ]]; then
|
||||
for disk in "$@"; do
|
||||
if [[ -b "$disk" ]]; then
|
||||
disks+=("$disk:direct")
|
||||
else
|
||||
print_color $RED "Error: $disk is not a valid block device"
|
||||
fi
|
||||
done
|
||||
else
|
||||
print_color $YELLOW "No NVMe drives found"
|
||||
# Auto-detect disks
|
||||
print_color $CYAN "Auto-detecting disks..."
|
||||
read -ra disks <<< "$(detect_raid_disks)"
|
||||
fi
|
||||
|
||||
# Check direct SATA/SAS drives
|
||||
print_color $MAGENTA "Checking direct SATA/SAS drives..."
|
||||
local direct_devices=()
|
||||
for dev in /dev/sd*; do
|
||||
if [[ -b "$dev" && "$dev" =~ /dev/sd[a-z]+$ ]]; then
|
||||
direct_devices+=("$dev")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#direct_devices[@]} -gt 0 ]]; then
|
||||
for dev in "${direct_devices[@]}"; do
|
||||
check_disk "$dev" ""
|
||||
if [[ ${#disks[@]} -eq 0 ]]; then
|
||||
print_color $YELLOW "No disks found via auto-detection"
|
||||
print_color $CYAN "Trying direct disk access..."
|
||||
for disk in /dev/sda /dev/sdb /dev/sdc /dev/nvme0n1; do
|
||||
if [[ -b "$disk" ]]; then
|
||||
disks+=("$disk:direct")
|
||||
fi
|
||||
done
|
||||
else
|
||||
print_color $YELLOW "No direct SATA/SAS drives found"
|
||||
fi
|
||||
|
||||
# Check drives behind RAID controllers
|
||||
for controller_type in "${raid_controllers[@]}"; do
|
||||
print_color $MAGENTA "Checking drives behind $controller_type controller..."
|
||||
|
||||
case $controller_type in
|
||||
megaraid)
|
||||
if command_exists storcli64; then
|
||||
local enclosures=$(storcli64 /c0 show | grep -E "^[0-9]+" | awk '{print $1}')
|
||||
for enc in $enclosures; do
|
||||
local drives=$(storcli64 /c0/e$enc/sall show | grep -E "^[0-9]+" | awk '{print $1}')
|
||||
for drive in $drives; do
|
||||
check_disk "/dev/sg$(echo $drive | cut -d':' -f1)" "megaraid,$drive"
|
||||
done
|
||||
done
|
||||
fi
|
||||
;;
|
||||
# Add other controller types as needed
|
||||
esac
|
||||
if [[ ${#disks[@]} -eq 0 ]]; then
|
||||
print_color $RED "No disks found or accessible"
|
||||
echo "Try running as root or specifying disk paths manually"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
print_color $GREEN "Found ${#disks[@]} disk(s) to check"
|
||||
echo ""
|
||||
|
||||
# Check each disk
|
||||
for disk_info in "${disks[@]}"; do
|
||||
IFS=':' read -r disk controller <<< "$disk_info"
|
||||
check_disk "$disk" "$controller"
|
||||
done
|
||||
|
||||
# Footer note
|
||||
print_color $BLUE "Check completed!"
|
||||
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 $CYAN "Script by $CREATOR"
|
||||
print_color $YELLOW "Note: SAS SSDs often do not expose write statistics through SMART."
|
||||
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
|
||||
show_help() {
|
||||
echo "Usage: $SCRIPT_NAME [OPTIONS]"
|
||||
echo "Check disk health for various types of storage devices"
|
||||
# Usage information
|
||||
usage() {
|
||||
echo "Usage: $SCRIPT_NAME [DISK1 DISK2 ...]"
|
||||
echo ""
|
||||
echo "Options:"
|
||||
echo " -h, --help Show this help message"
|
||||
echo " -v, --version Show version information"
|
||||
echo "If no disks specified, auto-detects all available disks and RAID arrays"
|
||||
echo ""
|
||||
echo "Supported storage types:"
|
||||
echo " - SATA HDD/SSD"
|
||||
echo " - SAS HDD/SSD"
|
||||
echo " - NVMe"
|
||||
echo " - RAID controllers (MegaRAID, 3ware, Areca, HP Smart Array, Adaptec)"
|
||||
echo " - Software RAID (MDRAID)"
|
||||
echo "Examples:"
|
||||
echo " $SCRIPT_NAME # Check all auto-detected disks"
|
||||
echo " $SCRIPT_NAME /dev/sda # Check specific disk"
|
||||
echo " $SCRIPT_NAME /dev/nvme0n1 # Check specific NVMe disk"
|
||||
echo " $SCRIPT_NAME /dev/sda /dev/nvme0n1 # Check multiple disks"
|
||||
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
|
||||
show_version() {
|
||||
echo "$SCRIPT_NAME version $VERSION"
|
||||
echo "Created by $CREATOR"
|
||||
}
|
||||
|
||||
# Main script execution
|
||||
# Parse command line arguments
|
||||
case "${1:-}" in
|
||||
-h|--help)
|
||||
show_help
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
-v|--version)
|
||||
show_version
|
||||
echo "$SCRIPT_NAME version $VERSION"
|
||||
echo "Created by Adam T. Lau"
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
check_all_disks
|
||||
main "$@"
|
||||
;;
|
||||
esac
|
||||
|
||||
Reference in New Issue
Block a user