Table of Contents
Smartctl
Modern drives allows to monitor its current state via SMART attributes. These values provide information about various parameters of the hard disk and can provide information on the disk's remaining lifespan or on any possible errors. In addition, various SMART tests can be performed to determine any hardware problems on the disk. On Linux smart support is provided by the package smartctl (Smartmontools).
Installation
The Smartmontools can be installed on Ubuntu using the package sources:
sudo apt-get install smartmontools
To ensure the hard disk supports SMART and is enabled, use the following command (in this example for the hard disk /dev/sda):
sudo smartctl -i /dev/sda smartctl 6.6 2017-11-05 r4594 [x86_64-linux-4.19.0-5-amd64] (local build) Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org === START OF INFORMATION SECTION === Model Family: Samsung based SSDs Device Model: Samsung SSD 850 PRO 1TB Serial Number: S252NWAG305759W LU WWN Device Id: 5 002538 8700cd57e Firmware Version: EXM02B6Q User Capacity: 1,024,209,543,168 bytes [1,02 TB] Sector Size: 512 bytes logical/physical Rotation Rate: Solid State Device Device is: In smartctl database [for details use: -P show] ATA Version is: ACS-2, ATA8-ACS T13/1699-D revision 4c SATA Version is: SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s) Local Time is: Sun Sep 1 10:11:27 2019 CEST SMART support is: Available - device has SMART capability. SMART support is: Enabled
Query Status
The status information of the drive can be queries with the following commands
sudo smartctl -a /dev/sda [Show all SMART information for device] sudo smartctl -x /dev/sda [Show all information for device]
Calculate Total Bytes Written
Smart attribute 241 (Total_LBAs_Written) can be used to derive the total bytes that have been written during the lifetime of the device.
sudo smartctl /dev/sda --all | grep Total_LBAs_Written 241 Total_LBAs_Written 0x0032 099 099 000 Old_age Always - 1479724000
The LBA consists of the sector size, which can be retrieved as follows:
sudo smartctl /dev/sda --all | grep "Sector Size" Sector Size: 512 bytes logical/physical
Total bytes written during the lifetime of the device, can now be calculated:
Total LBA 1.479.724.000 Sector Size 512 Total Bytes 757.618.688.000 Total KB 739.862.000 Total MB 729.647 Total GB 720
ATA Tests
Short Test
Purpose is a rapid identification of a defective hard drive. Therefore, a maximum run time for the short test is 2 min. The test checks the disk by dividing it into three different segments. The following areas are tested:
- 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.
- Mechanical Properties: The exact sequence of the servos and the positioning mechanism to be tested is also specific to each manufacturer.
- 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.
Check available tests
Before performing a test, an approximate indication of the time duration of the various tests are displayed using the following command:
sudo smartctl -c /dev/sda Example output: [.....] Short self-test routine recommended polling time: ( 2) minutes. Extended self-test routine recommended polling time: ( 543) minutes. [.....]
Start a test
The following command starts the desired test (in Background Mode):
sudo smartctl -t <short|long> /dev/sda
It is also possible to perform an Foreground (offline) Mode test. However, only the standard self test (Short Test) is performed. To perform the tests in Foreground (offline) Mode a “-C” must be added to the command.
sudo smartctl -t <short|long> -C /dev/sda
Example output: smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.5.0-39-generic] (local build) Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net === 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 Mon Sep 2 15:32:30 2013 Use smartctl -X to abort test.
View test results
In general, the test results are included in the output of the following commands:
sudo smartctl -a /dev/sda
Example:
[...]
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% 2089 -
# 2 Extended offline Completed without error 00% 2087 -
# 3 Short offline Completed without error 00% 2084 -
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.
[...]
The following command can also be used, if only the test results should are displayed:
sudo smartctl -l selftest /dev/sda Example output: smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.5.0-39-generic] (local build) Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net === 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% 2089 - # 2 Extended offline Completed without error 00% 2087 - # 3 Short offline Completed without error 00% 2084 -
