Implement drive health check for thinkpad

This commit is contained in:
Yan Lin 2025-09-14 13:51:56 +02:00
parent a8dd25576e
commit fd8a537a18
8 changed files with 224 additions and 54 deletions

View file

@ -18,32 +18,64 @@
# Global smartd options
extraOptions = [ "-A /var/log/smartd/" "-i 600" ];
# Disable default notifications
notifications = {
mail.enable = false;
x11.enable = false;
test = false;
};
# Device-specific monitoring configurations
devices = [
# ZFS Mirror drives (NVMe SSDs) - more frequent monitoring
{
device = "/dev/disk/by-id/ata-ZHITAI_SC001_XT_1000GB_ZTB401TAB244431J4R";
options = "-d auto -a -o on -S on -s (S/../.././02|L/../../6/03) -m exec=/home/yanlin/.config/nix/scripts/disk-health-smartd-alert.sh";
options = "-d auto -a -o on -S on -s (S/../.././02|L/../../6/03) -M exec ${pkgs.writeShellScript "smartd-notify-hs-zfs1" ''
export SMARTD_DEVICE="$SMARTD_DEVICE"
export SMARTD_FAILTYPE="$SMARTD_FAILTYPE"
export SMARTD_MESSAGE="$SMARTD_MESSAGE"
/home/yanlin/.config/nix/scripts/disk-health-smartd-alert.sh Ac9qKFH5cA.7Yly ZFS_Mirror_1
''}";
}
{
device = "/dev/disk/by-id/ata-ZHITAI_SC001_XT_1000GB_ZTB401TAB244431KEG";
options = "-d auto -a -o on -S on -s (S/../.././02|L/../../6/03) -m exec=/home/yanlin/.config/nix/scripts/disk-health-smartd-alert.sh";
options = "-d auto -a -o on -S on -s (S/../.././02|L/../../6/03) -M exec ${pkgs.writeShellScript "smartd-notify-hs-zfs2" ''
export SMARTD_DEVICE="$SMARTD_DEVICE"
export SMARTD_FAILTYPE="$SMARTD_FAILTYPE"
export SMARTD_MESSAGE="$SMARTD_MESSAGE"
/home/yanlin/.config/nix/scripts/disk-health-smartd-alert.sh Ac9qKFH5cA.7Yly ZFS_Mirror_2
''}";
}
# Data drives (12TB HDDs) - standard monitoring
{
device = "/dev/disk/by-id/ata-HGST_HUH721212ALE604_5PK2N4GB";
options = "-d auto -a -o on -S on -s (S/../.././02|L/../../7/03) -W 4,45,55 -m exec=/home/yanlin/.config/nix/scripts/disk-health-smartd-alert.sh";
options = "-d auto -a -o on -S on -s (S/../.././02|L/../../7/03) -W 4,45,55 -M exec ${pkgs.writeShellScript "smartd-notify-hs-data1" ''
export SMARTD_DEVICE="$SMARTD_DEVICE"
export SMARTD_FAILTYPE="$SMARTD_FAILTYPE"
export SMARTD_MESSAGE="$SMARTD_MESSAGE"
/home/yanlin/.config/nix/scripts/disk-health-smartd-alert.sh Ac9qKFH5cA.7Yly Data_Drive_1_12TB
''}";
}
{
device = "/dev/disk/by-id/ata-HGST_HUH721212ALE604_5PJ7Z3LE";
options = "-d auto -a -o on -S on -s (S/../.././02|L/../../7/03) -W 4,45,55 -m exec=/home/yanlin/.config/nix/scripts/disk-health-smartd-alert.sh";
options = "-d auto -a -o on -S on -s (S/../.././02|L/../../7/03) -W 4,45,55 -M exec ${pkgs.writeShellScript "smartd-notify-hs-data2" ''
export SMARTD_DEVICE="$SMARTD_DEVICE"
export SMARTD_FAILTYPE="$SMARTD_FAILTYPE"
export SMARTD_MESSAGE="$SMARTD_MESSAGE"
/home/yanlin/.config/nix/scripts/disk-health-smartd-alert.sh Ac9qKFH5cA.7Yly Data_Drive_2_12TB
''}";
}
# Parity drive (16TB HDD) - enhanced monitoring due to criticality
{
device = "/dev/disk/by-id/ata-ST16000NM000J-2TW103_WRS0F8BE";
options = "-d auto -a -o on -S on -s (S/../.././02|L/../../1/03) -W 2,45,55 -m exec=/home/yanlin/.config/nix/scripts/disk-health-smartd-alert.sh";
options = "-d auto -a -o on -S on -s (S/../.././02|L/../../1/03) -W 2,45,55 -M exec ${pkgs.writeShellScript "smartd-notify-hs-parity" ''
export SMARTD_DEVICE="$SMARTD_DEVICE"
export SMARTD_FAILTYPE="$SMARTD_FAILTYPE"
export SMARTD_MESSAGE="$SMARTD_MESSAGE"
/home/yanlin/.config/nix/scripts/disk-health-smartd-alert.sh Ac9qKFH5cA.7Yly Parity_Drive_16TB
''}";
}
];
};
@ -56,14 +88,17 @@
after = [ "multi-user.target" ];
serviceConfig = {
Type = "oneshot";
ExecStart = "${pkgs.bash}/bin/bash /home/yanlin/.config/nix/scripts/daily-smart-report.sh";
ExecStart = "${pkgs.bash}/bin/bash /home/yanlin/.config/nix/scripts/daily-smart-report.sh Ac9qKFH5cA.7Yly";
User = "root";
StandardOutput = "journal";
StandardError = "journal";
# Add timeout to prevent hanging
TimeoutStartSec = "300"; # 5 minutes max
# Set PATH to include system binaries for smartctl and curl
Environment = "PATH=/run/current-system/sw/bin";
# Set PATH and SMART_DRIVES environment variables
Environment = [
"PATH=/run/current-system/sw/bin"
"SMART_DRIVES=/dev/disk/by-id/ata-ZHITAI_SC001_XT_1000GB_ZTB401TAB244431J4R:ZFS Mirror 1;/dev/disk/by-id/ata-ZHITAI_SC001_XT_1000GB_ZTB401TAB244431KEG:ZFS Mirror 2;/dev/disk/by-id/ata-HGST_HUH721212ALE604_5PK2N4GB:Data Drive 1 (12TB);/dev/disk/by-id/ata-HGST_HUH721212ALE604_5PJ7Z3LE:Data Drive 2 (12TB);/dev/disk/by-id/ata-ST16000NM000J-2TW103_WRS0F8BE:Parity Drive (16TB)"
];
# Allow access to block devices for SMART commands
DeviceAllow = [ "/dev/disk/by-id/* rw" "/dev/sd* rw" "/dev/nvme* rw" "char-* rw" "block-* rw" ];
DevicePolicy = "closed";

View file

@ -9,7 +9,7 @@
# hs-specific home configuration
programs.zsh.shellAliases = {
# Disk health monitoring
smart-report = "sudo /home/yanlin/.config/nix/scripts/daily-smart-report.sh";
smart-report = "sudo SMART_DRIVES='/dev/disk/by-id/ata-ZHITAI_SC001_XT_1000GB_ZTB401TAB244431J4R:ZFS Mirror 1;/dev/disk/by-id/ata-ZHITAI_SC001_XT_1000GB_ZTB401TAB244431KEG:ZFS Mirror 2;/dev/disk/by-id/ata-HGST_HUH721212ALE604_5PK2N4GB:Data Drive 1 (12TB);/dev/disk/by-id/ata-HGST_HUH721212ALE604_5PJ7Z3LE:Data Drive 2 (12TB);/dev/disk/by-id/ata-ST16000NM000J-2TW103_WRS0F8BE:Parity Drive (16TB)' /home/yanlin/.config/nix/scripts/daily-smart-report.sh Ac9qKFH5cA.7Yly";
move-inbox = "cp -rl /mnt/storage/Media/downloads/.inbox/* /mnt/storage/Media/downloads/inbox && chown -R yanlin:users /mnt/storage/Media/downloads/inbox";
};