72

I am testing a hard disk with SmartMonTools.

Hard disk status prior to the testings (only one short test performed days ago):

$ sudo smartctl -l selftest /dev/sda
smartctl 6.2 2013-07-26 r3841 [i686-linux-3.16.0-30-generic] (local build)
Copyright (C) 2002-13, 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       Completed without error       00%      5167         -

So I start the long test:

$ sudo smartctl -t long /dev/sda
smartctl 6.2 2013-07-26 r3841 [i686-linux-3.16.0-30-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 Extended self-test routine immediately in off-line mode".
Drive command "Execute SMART Extended self-test routine immediately in off-line mode" successful.
Testing has begun.
Please wait 130 minutes for test to complete.
Test will complete after Sat May  9 16:05:27 2015

Use smartctl -X to abort test.

The test is supposed to be running, then, but if I try to see its progress:

$ sudo smartctl -l selftest /dev/sda
smartctl 6.2 2013-07-26 r3841 [i686-linux-3.16.0-30-generic] (local build)
Copyright (C) 2002-13, 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       Completed without error       00%      5167         -

... all I get is the same results, like if there were no running/performing tests right now.
The '-H' parameter gives no more info:

$ sudo smartctl -H /dev/sda
smartctl 6.2 2013-07-26 r3841 [i686-linux-3.16.0-30-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

And, as long as there is no process running (this test is performed by the hard disk controller alone), some ps -e style search should neither help.

How can I know if there is some SMART self test running right now?

Sopalajo de Arrierez
  • 6,281
  • 21
  • 60
  • 98

2 Answers2

83

In smartctl -a <device> look for Self-test execution status.

Example when no test is running:

Self-test execution status:      (   0) The previous self-test routine completed
                                        without error or no self-test has ever
                                        been run.

Example while a test is running:

Self-test execution status:      ( 249) Self-test routine in progress...
                                        90% of test remaining.

When running selective self-test (-t select) there will also be a progress shown here:

SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA    MAX_LBA  CURRENT_TEST_STATUS
    1        0  125045423  Self_test_in_progress [90% left] (2881512-2947047)
Adi Prasetyo
  • 141
  • 1
  • 11
frostschutz
  • 47,228
  • 5
  • 112
  • 159
  • 12
    A good idea. I suggest you to add this direct line (by grepping) as a possibility: `smartctl -a /dev/sda | grep "progress" -i -A 1` , to cut excessive info printout. – Sopalajo de Arrierez May 09 '15 at 11:18
  • 2
    You need the excessive printout to get the whole picture though. In a script the grep may be fine, but people who are used to `grep` everything on the command line (`dmesg | grep something`, `smartctl -a | grep ...`, etc.), they will miss things. With `smartctl` in particular there is no simple command that tells you everything is okay... `smartctl -H` is a false friend in that regard. – frostschutz May 09 '15 at 12:09
  • @frostschutz "smartctl -H is a false friend in that regard." You can say that again! I too have fallen for this option once, thinking it might have to do with the self-tests...but no, entirely different subject (and purpose). – syntaxerror Jan 29 '16 at 21:03
  • What do I do for "Device does not support Self Test logging"? – Mr.WorshipMe Jul 27 '17 at 19:29
  • I have `Self-test execution status:` at `241` and it is telling me `10% of test remaining` for 4 hours now on a 14TB USB drive. – bomben Dec 01 '20 at 00:39
  • 3
    @Ben yes, some drives don't seem to report these correctly. Instead of `-t long` you can try selective `-t select,0-max`. Technically this does the very same thing as `-t long` but it might have a more accurate progress report in the Selective self-test log section. Personally [I use selective self-test with smaller slices](https://unix.stackexchange.com/a/92663/30851) so I can run short daily tests. A long test run just takes ages on xx TB HDDs and not every machine runs 24/7 to let it finish. – frostschutz Dec 01 '20 at 08:06
  • The command ``sudo smartctl -a /dev/sdX | grep "of test"`` will provide a single line with percent remaining. – oemb1905 Sep 08 '21 at 03:49
21

Try :

smartctl -c /dev/sda

if /dev/sda is the drive you want to check.

SebM
  • 211
  • 2
  • 2
  • 1
    Edit: Sorry. I was wrong. -c means --capabilities but it too shows the current test progress. like `60% of test remaining.` – JPT Nov 02 '19 at 17:03