Smartmontools and Smartctl Cheatsheet
Modern storage drives come with the Self-Monitoring, Analysis and Reporting Technology, or SMART for short. This is a monitoring system that detects and reports on various indicators of drive reliability, with the intent of enabling the anticipation of hardware failures. Smartmontools is the package that installs the smartctl command that you can use to take advantage of this functionality.
Table Of Contents
Installation (Ubuntu)
sudo apt-get install smartmontools -y
Fetch Information About A Device
sudo smartctl -i /dev/sd[x]
Example output:
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.19.0-49-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF INFORMATION SECTION ===
Model Family: Western Digital Red (AF)
Device Model: WDC WD30EFRX-68EUZN0
Serial Number: WD-WCC4N1TD13LC
LU WWN Device Id: 5 0014ee 26102d3aa
Firmware Version: 82.00A82
User Capacity: 3,000,592,982,016 bytes [3.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: 3.0 Gb/s)
Local Time is: Sun Feb 7 10:39:16 2016 GMT
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
Check Health Information
sudo smartctl -H /dev/sd[x]
Example output:
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.19.0-49-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
More Detail
To get more detail, run the following:
sudo smartctl -a /dev/sd[x]
Testing
List Tests and Durations.
Usually, you can choose between running a short test or a long test. For an SSD, I would always recommend running the long test as it is always so quick. However, with HDDs, the long test can take many hours, if not more than a day, so you have to think carefully about whether a short test would suffice. Luckily, you can find out how long a test should need to run for with the command below:
sudo smartctl -c /dev/sd[x]
The output of the command will contain within it the test details:
...
Short self-test routine
recommended polling time: ( 2) minutes.
Extended self-test routine
recommended polling time: ( 410) minutes.
Conveyance self-test routine
recommended polling time: ( 5) minutes.
...
Run a Short Test
sudo smartctl -t short /dev/sd[x]
Example output:
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.19.0-49-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===
Sending command: "Execute SMART Short self-test routine immediately in off-line mode".
Drive command "Execute SMART Short self-test routine immediately in off-line mode" successful.
Testing has begun.
Please wait 2 minutes for test to complete.
Test will complete after Sun Feb 7 10:46:37 2016
Use smartctl -X to abort test.
Run a Long Test
sudo smartctl -t long /dev/sd[x]
Check Test Progress
This actually can vary, so I have outlined what I have found below.
Method 1
I have found that with my older Crucial MX SSDs, they will show the test progress in the output from running the list test results command. E.g. the test you just scheduled will show up immediately, rather than only after it has completed, and show you how long is remaning like below:
stuart@stuart-acer:~$ sudo smartctl -l selftest /dev/sdb
smartctl 7.1 2019-12-30 r5022 [x86_64-linux-5.4.0-162-generic] (local build)
Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org
=== START OF READ SMART DATA SECTION ===
SMART Self-test log structure revision number 1
Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error
# 1 Short offline Self-test routine in progress 90% 40066 -
# 2 Extended offline Completed without error 00% 40065 -
# 3 Vendor (0xff) Completed without error 00% 40065 -
# 4 Vendor (0xff) Completed without error 00% 40063 -
Method 2
I have found that with Samsung SSDs and my newer Crucial MX SSD, there is no check to see how much progress has been made, but if you run the command for scheduling a test whilst it is still running, you will see:
=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===
Can't start self-test without aborting current test (10% remaining),
add '-t force' option to override, or run 'smartctl -X' to abort test.
Which does give you an indication of progress (it says the percentage remaining in the output).
List test Results
sudo smartctl -l selftest /dev/sd[x]
Obviously if you see no results, you know that the test hasn't yet completed.
References
- Wikipedia - S.M.A.R.T.
- Monitoring Hard Drive Health on Linux with smartmontools
- Ubuntu manuals - smartctl
- nixCraft - Test If Linux Server SCSI / SATA Hard Disk Going Bad
First published: 16th August 2018