Smartctl

From HPCWIKI
Jump to navigation Jump to search

smartmontools.org supports the smartctl Command Line Tool of Smartmontoolsis primarily used to query SMART attributes of hard drives and SSDs.[1]

Recently, Alexander Shaduri released ​a graphical user interface for smartctl called as GSmartControl[2] available for Linux, FreeBSD, MacOS X and Windows.

smartctl

Option Action
-h, --help Prints out a table with a brief overview of the commands and their syntax
--scan scans all devices and prints out their names, type and protocol.
-d TYPE smartctl will guess the device type, but if you need to specify it manually you can do so with this switch. eg (ata, scsi, nvme, see man page for full list etc)
-i, --info prints various information about the device
-H, --health Reports SMART health status. On “fail” status the drive is already dead or will die very soon.
-a, --all Prints all SMART info about device. I recommended piping the output to less, more, or pager.
-s (on, off) Enable/disable SMART on device.
-o (on, off) ATA only, enable/disable SMART automatic offline test (checks disk every 4 hours for defects)
-x, --xall prints all SMART and non-SMART information about the device.
-S (on, off) Enables/disables SMART autosave of device vendor attributes. Needs only be ran once and preserves this data even if disk is powered off.
# scans all drives and type
smartctl --scan

# -i gives a brief overview of the drive and status of supports SMART and is enabled
sudo smartctl -i /dev/nvme0

# -a will print out a large amount of information and stats; piped to pager
sudo smartctl -d ata -a -i /dev/sda | pager #or more or less

# enable SMART and offline testing on device
sudo smartctl -s on -o on -S on /dev/sdb

# check smart health with -H (Healthy status)
sudo smartctl -d scsi -H /dev/sdc

--scan switch to get the type of drives in the system

Available Tests[3][4]

  • Foreground Mode - recommended when the hard disk is not used
  • Background Mode - preferred mode, test executed in low priority. If the hard drive is busy, the test is paused and then continues at a lower load speed, so there is no interruption of the operation

Basic smartctl command

To disable smartctl smartctl -o off device
Check drive health smartctl -H device
Run long/short test smartctl <short or long> device sudo smartctl -t <short|long|conveyance|select> /dev/sdc

tests in Foreground Mode a "-C" must be added to the command. sudo smartctl -t <short|long|conveyance|select> -C /dev/sdc

To abort test Use smartctl -X
View full results smartctl -a device
View limited results sudo smartctl -A device

smartctl -l error device

smartctl test case

Test Test case
ATA/SCSI Tests Short Test rapid identification of a defective hard drive in three different segments. Therefore, a maximum run time for the short test is 2 min.
  1. Electrical Properties: The controller tests its own electronics, and since this is specific to each manufacturer, it cannot be explained exactly what is being tested. It is conceivable, for example, to test the internal RAM, the read/write circuits or the head electronics.
  2. Mechanical Properties: The exact sequence of the servos and the positioning mechanism to be tested is also specific to each manufacturer.
  3. Read/Verify: It will read a certain area of ​​the disk and verify certain data, the size and position of the region that is read is also specific to each manufacturer.
Long Test The long test was designed as the final test in production and is the same as the short test with two differences. The first: there is no time restriction and in the Read/Verify segment the entire disk is checked and not just a section. The Long test can, for example, be used to confirm the results of the short tests.
ATA specified Tests Conveyance Test This test can be performed to determine damage during transport of the hard disk within just a few minutes.
Select Tests During selected tests the specified range of LBAs is checked. The LBAs to be scanned are specified in the following formats:
sudo smartctl -t select,10-20 /dev/sdc #LBA 10 to LBA 20 (incl.)
sudo smartctl -t select,10+11 /dev/sdc #LBA 10 to LBA 20 (incl.)

It is also possible to have multiple ranges, (up to 5), to scan:

sudo smartctl -t select,0-10 -t select,5-15 -t select,10-20 /dev/sdc

smartd using systemd

smartmontool log file will be storea at /var/lib/smartmontools. smartmontool can also run in the background and have it check drives and email when there are issues, This Ubuntu page shows more details.

Option Action
-q WHEN Tells smartd when to quit. See full man page for full details. One useful option is onecheck, which registers attached devices and checks the status of the devices exactly once and returns this as text output.
-d, --debug verbose status information, and does not fork into the background, in this mode, CTRL+C will not exit the readout but instead reload the smartd config, to exit this mode use CTRL+\.
h prints help and command summary
-i N, --interval N Sets how often smartd will check disk in seconds, default is 1800 secs or 30 minutes.

smartd commandline examples

#register and check all devices once
smartd -q onecheck

# run in foreground in debug mode, checking polling every device every 15 seconds
# exit with ctrl+\
smartd -d -i 15

#running smartd on its own will run in the daemon in the background and log to syslog
smartd

# with systemd service
sudo systemctl start smartd.service
sudo systemctl stop smartd.service
sudo systemctl restart smartd.service

Configuring /etc/smartd.conf

smartd is configurable via /etc/smartd.conf

sudo vim /etc/smartd.conf
#...
#DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner
DEVICESCAN -a -m your@mxdomain.com -M test
#...

some more examples
#monitors /dev/sda and preforms a long test every sunday between 2-3am
/dev/sda -d scsi -a -s L/../../7/02

# Only reports SMART health failures to a email addres
/dev/sdc -H -C 0 -U 0 your@mxdomain.com

#save

#Restart smartd service 
sudo systemctl restart smartmontools.

Configuring /etc/smartd.conf with all hdd behind of controller

#list up all DID 
for i in $(storcli /c0 /eall /sall show | grep "^22"|awk '{print $2}'); do echo "/dev/sda -a -d megaraid,$i <do something>; done
/dev/sda -a -d megaraid,24 <do something>
/dev/sda -a -d megaraid,25 <do something>
/dev/sda -a -d megaraid,10 <do something>
/dev/sda -a -d megaraid,11 <do something>
/dev/sda -a -d megaraid,12 <do something>
...

/dev/sda -a -d megaraid,21 <do something> 
# <do something> example, -m root -M exec /usr/share/smartmontools/smartd-runner

Following table is basic directives of the /etc/smartd.conf file and meaning[5]

Option Action
-a Equivalent to running -H -f -t -l error -l selftest -C 197 -U 198
-H Monitor SMART Health, and report failures
-f Monitor for failure of any 'Usage' Attributes
-t Equivalent to -p and -u
-p Report changes in 'Prefailure' attributes
-u Report changes in 'Usage' attributes
-l TYPE Monitor SMART log. options are (error | selftest)
-C ID Report Current Pending Sector counts
-U ID Report Offline Uncorrectable counts
-m Send warning email with results of -H, -l, and -f
-M Type See the man page for other options. Using -M test, Sends a test email an service start.
-d TYPE Specifies type of devices just like smartctl
-W (D,I,C) Monitor temperature Difference, Informal limit, & Critical limit.
-s (L/../../7/02) Schedule tests using REGEXP, see man.

This guide shows how to configure smartd and be notified of hard disk problems via email using msmtp

Check RAID array list

can display which disks of the RAID controller are accessible.

cat /proc/scsi/scsi

smartctl disks behind LSI array

smartctl provides integrated support for MegaRAID controller

sudo smartctl -a -d megaraid,<StorCLI column DID value>  /dev/sdX

Where <N> stands for the DID (Device ID) on the RAID controller. These can be displayed via the StorCLI (column DID).

sudo storcli /c0 /eall /sall show

Test all N drives[6]

for i in {0..N}; do sudo smartctl -t short /dev/sda -d megaraid,$i >>./OUTPUT; done

smartctl behind by HW RAID by manufacturer[7]

Manufacturer Hard disk Command
ARECA 1 smartctl -x /dev/sg1 -d areca,1
ARECA 2 smartctl -x /dev/sg1 -d areca,2
LSI / 3Ware 1 smartctl -x /dev/twe0 -d 3ware,0
LSI / 3Ware 2 smartctl -x /dev/twe0 -d 3ware,1
Adaptec 1 smartctl -x /dev/sg2 -d sat
Adaptec 2 smartctl -x /dev/sg3 -d sat
Adaptec (3) smartctl -x /dev/sg4 -d sat
Adaptec (4) smartctl -x /dev/sg5 -d sat
Dell 1 smartctl –x -d sat+megaraid,0 /dev/sda
Dell 2 smartctl –x -d sat+megaraid,1 /dev/sda
Broadcom 1 smartctl –x -d sat+megaraid,0 /dev/sda
Broadcom 2 smartctl –x -d sat+megaraid,1 /dev/sda                                           

Identify a defective hard drive

  1. Check "START OF READ SMART DATA SECTION" from smartctl. If the value Failed or UNKNOWN is displayed instead of the value PASSED, you should replace the hard drive as soon as possible
  2. Check "WHEN_FAILED", If the Attribute's current Normalized value is less than or equal to the threshold value, then the "WHEN_FAILED" column will display "FAILING_NOW". If not, but the worst recorded value is less than or equal to the threshold value, then this column will display "In_the_past". If the "WHEN_FAILED" column has no entry (indicated by a dash: '-') then this Attribute is OK now (not failing) and has also never failed in the past.[8]
  3. Some important attributes are following
Attribute name Description
Reallocated_Sector_Ct Specifies the number of sectors reassigned due to read errors. If a sector can no longer be read, written to or checked correctly, a replacement sector is automatically assigned to it. The faulty sector is permanently marked as unreadable. This is a clear warning sign for incipient surface problems. If this value is not equal to zero, a hard drive failure is often imminent. This value is the most important indicator for a hard drive replacement
Current_Pending_Sector_Ct Specifies the number of unstable sectors waiting for remapping. If a sector cannot be read and written correctly, it first receives the status Current Pending Sector. The sector is not reassigned in this state, since the data in the sector are unknown. Only after several unsuccessful read or write attempts is a replacement sector assigned and the faulty sector is permanently marked as unreadable. The value Current_Pending_Sector_Ct is an important indicator for a hard drive replacement.

If this value is not equal to zero, a hard drive failure is often imminent

Offline_Uncorrectable Specifies the number of uncorrectable write and read sector errors.

The last section deals with the internal hard drive log. Errors are recorded here if the server's work orders have not been processed correctly by the hard drive. If the number of errors in this section is at least two digits, you should replace the hard drive as soon as possible

#smartctl example output
$ sudo smartctl -a /dev/sda
smartctl 7.1 2019-12-30 r5022 [x86_64-linux-5.4.0-164-generic] (local build)
Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Western Digital Red
Device Model:     WDC WD40EFRX-68WT0N0
Serial Number:    WD-WCC4E7JN0YCY
LU WWN Device Id: 5 0014ee 262e50378
Firmware Version: 82.00A82
User Capacity:    4,000,787,030,016 bytes [4.00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    5400 rpm
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ACS-2 (minor revision not indicated)
SATA Version is:  SATA 3.0, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Sun Dec 10 13:01:01 2023 KST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x00) Offline data collection activity
                                        was never started.
                                        Auto Offline Data Collection: Disabled.
Self-test execution status:      (   0) The previous self-test routine completed
                                        without error or no self-test has ever 
                                        been run.
Total time to complete Offline 
data collection:                (51540) seconds.
Offline data collection
capabilities:                    (0x7b) SMART execute Offline immediate.
                                        Auto Offline data collection on/off support.
                                        Suspend Offline collection upon new
                                        command.
                                        Offline surface scan supported.
                                        Self-test supported.
                                        Conveyance Self-test supported.
                                        Selective Self-test supported.
SMART capabilities:            (0x0003) Saves SMART data before entering
                                        power-saving mode.
                                        Supports SMART auto save timer.
Error logging capability:        (0x01) Error logging supported.
                                        General Purpose Logging supported.
Short self-test routine 
recommended polling time:        (   2) minutes.
Extended self-test routine
recommended polling time:        ( 515) minutes.
Conveyance self-test routine
recommended polling time:        (   5) minutes.
SCT capabilities:              (0x703d) SCT Status supported.
                                        SCT Error Recovery Control supported.
                                        SCT Feature Control supported.
                                        SCT Data Table supported.

SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x002f   200   200   051    Pre-fail  Always       -       0
  3 Spin_Up_Time            0x0027   182   182   021    Pre-fail  Always       -       7875
  4 Start_Stop_Count        0x0032   100   100   000    Old_age   Always       -       22
  5 Reallocated_Sector_Ct   0x0033   200   200   140    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x002e   200   200   000    Old_age   Always       -       0
  9 Power_On_Hours          0x0032   069   068   000    Old_age   Always       -       22749
 10 Spin_Retry_Count        0x0032   100   253   000    Old_age   Always       -       0
 11 Calibration_Retry_Count 0x0032   100   253   000    Old_age   Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       22
192 Power-Off_Retract_Count 0x0032   200   200   000    Old_age   Always       -       11
193 Load_Cycle_Count        0x0032   180   180   000    Old_age   Always       -       60592
194 Temperature_Celsius     0x0022   117   105   000    Old_age   Always       -       35
196 Reallocated_Event_Count 0x0032   200   200   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0032   200   200   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0030   100   253   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x0032   200   200   000    Old_age   Always       -       0
200 Multi_Zone_Error_Rate   0x0008   100   253   000    Old_age   Offline      -       0

Check latest version

References