How to Check SSD/HDD health in Linux

If you are a system administrator and responsible for managing Linux systems in Datacenter. Then, it is recommended to check the health of the SSD and HDD drives regularly. It will help you to identify failed drives and they can be replaced before any data loss occurs. S.M.A.R.T is a tool used to monitor the health status of SSD and HDD. It also allows you to perform on-demand tests on the drive.

In this post, we will show you how to check SSD and HDD health on Linux.

Prerequisites

  • A server or Desktop running Linux operating system.
  • A root password is configured on the server.

Install Smartctl

By default, Smartctl is included in the default repository of all major Linux distributions.

For Debian and Ubuntu distribution, install Smartctl using the following command:

apt-get install smartmontools -y

For RHEL, CentOS, and Fedora distribution, install Smartctl using the following command:

dnf install smartmontools

After installing Smartctl, start the Smartctl service using the following command:

systemctl start smartd

You can check the status of the smartd with the following command:

systemctl status smartd

You should get the following output:

? smartmontools.service - Self Monitoring and Reporting Technology (SMART) Daemon
     Loaded: loaded (/lib/systemd/system/smartmontools.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2021-07-02 08:58:33 UTC; 11s ago
       Docs: man:smartd(8)
             man:smartd.conf(5)
   Main PID: 1042 (smartd)
     Status: "Next check of 0 devices will start at 09:28:33"
      Tasks: 1 (limit: 2353)
     Memory: 1.2M
     CGroup: /system.slice/smartmontools.service
             ??1042 /usr/sbin/smartd -n

Jul 02 08:58:33 ubuntu2004 smartd[1042]: Device: /dev/sda, opened
Jul 02 08:58:33 ubuntu2004 smartd[1042]: Device: /dev/sda, [QEMU     QEMU HARDDISK    2.5+], 53.6 GB
Jul 02 08:58:33 ubuntu2004 smartd[1042]: Device: /dev/sda, IE (SMART) not enabled, skip device
Jul 02 08:58:33 ubuntu2004 smartd[1042]: Try 'smartctl -s on /dev/sda' to turn on SMART features
Jul 02 08:58:33 ubuntu2004 smartd[1042]: Device: /dev/sdb, opened
Jul 02 08:58:33 ubuntu2004 smartd[1042]: Device: /dev/sdb, [AN       Volume           2.5+], S/N: sdb, 53.6 GB
Jul 02 08:58:33 ubuntu2004 smartd[1042]: Device: /dev/sdb, IE (SMART) not enabled, skip device
Jul 02 08:58:33 ubuntu2004 smartd[1042]: Try 'smartctl -s on /dev/sdb' to turn on SMART features
Jul 02 08:58:33 ubuntu2004 smartd[1042]: Monitoring 0 ATA/SATA, 0 SCSI/SAS and 0 NVMe devices
Jul 02 08:58:33 ubuntu2004 systemd[1]: Started Self Monitoring and Reporting Technology (SMART) Daemon.

Test Health of SSD/HDD

After installing Smartctl, you will need to turn on SMART features on your hard drive.

You can do it using the following command:

smartctl -s on /dev/sda

The first thing you will need to do is to obtain information of SSD or HDD.

You can done it using the following command:

smartctl -i /dev/sda

This will give you the detailed information of your hard drive.

smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-148-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Device Model:     WDC WD5000LPVX-75V0TT0
Serial Number:    WXV1EC4KN2N7
LU WWN Device Id: 5 0014ee 65af65611
Firmware Version: 01.01A01
User Capacity:    500,107,862,016 bytes [500 GB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    5400 rpm
Device is:        Not in smartctl database [for details use: -P showall]
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:    Fri Jul  2 14:39:33 2021 IST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

If you want to perform a short test on the drive, run the following command:

smartctl -t short -a /dev/sda

You should get the following output:

smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-148-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Device Model:     WDC WD5000LPVX-75V0TT0
Serial Number:    WXV1EC4KN2N7
LU WWN Device Id: 5 0014ee 65af65611
Firmware Version: 01.01A01
User Capacity:    500,107,862,016 bytes [500 GB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    5400 rpm
Device is:        Not in smartctl database [for details use: -P showall]
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:    Fri Jul  2 14:40:23 2021 IST
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: 		( 9360) seconds.
Offline data collection
capabilities: 			 (0x7b) SMART execute Offline immediate.
					Auto Offline data collection on/off support.

The short test will test the Electrical Properties, Mechanical Properties, and Read/Verify.

To find and print the self-test result, run the following command:

smartctl -l selftest /dev/sda

You should get the following output:

smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-148-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%      7609         -
# 2  Short offline       Interrupted (host reset)      90%      6972         -
# 3  Short offline       Aborted by host               70%      6972         -
# 4  Short offline       Interrupted (host reset)      70%         2         -

To run a long test, use the following command:

smartctl -t long -a /dev/sda

You should get the following output:

SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.

=== 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 107 minutes for test to complete.
Test will complete after Fri Jul  2 16:30:41 2021

Use smartctl -X to abort test.
 

The long test will test everything included with the short test.

You can stop the test, run the following command:

smartctl -X /dev/sda

You should see the following output:

smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-148-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===
Sending command: "Abort SMART off-line mode self-test routine".
Self-testing aborted!

To test the overall health of the drive, run the following command:

smartctl -d ata -H /dev/sda

You should get the following output:

smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-148-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

To check estimated time to perform the test, run the following command:

smartctl -c /dev/sda

You should get the following output:

smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-148-generic] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
General SMART Values:
Offline data collection status:  (0x00)	Offline data collection activity
					was never started.
					Auto Offline Data Collection: Disabled.
Self-test execution status:      (  25)	The self-test routine was aborted by
					the host.
Total time to complete Offline 
data collection: 		( 9360) 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: 	 ( 107) minutes.
Conveyance self-test routine
recommended polling time: 	 (   5) minutes.
SCT capabilities: 	       (0x7035)	SCT Status supported.
					SCT Feature Control supported.
					SCT Data Table supported.

To print only the error log, run the following command:

smartctl -l error /dev/sda

To get help information, run the following command:

smartctl --help

Conclusion

In the above guide, you learned how to install and use the S.M.A.R.T tool to check the health of your SSH and HDD drives. I hope this will help you a lot. For more information, read the smartctl man page

Share this page:

Suggested articles

1 Comment(s)

Add comment

Comments

By: Davo at: 2021-07-02 23:23:28

How to setup smart to run weekly short tests and monthly long tests, save the output to files rotated every 6 months?  Running a command or 2 manually isn't great when SMART has a built-in automatic solution for those things.