The Linux smartctl command: health diagnosis of the disk
In modern system management, hardware failure prevention is as critical as software management. Storage disks, whether mechanical hard (HDD) or solid state units (SSD), are subject to physical wear and errors that can compromise data integrity. Fortunately, most of these devices incorporate the S.M.A.R.T. (Self-Monitoring, Analysis and Reporting Technology) technology, which continuously monitors internal attributes such as temperature, reassigned sectors and access times. In Linux environments, the commandsmartctl, part of the packagesmartmontools, is the most powerful command line tool to interact with this technology, allowing administrators to obtain accurate diagnoses, run fault detection tests and take corrective action before a catastrophic loss of information occurs.
Installation of smartmontools in popular Linux distributions
Before usesmartctl, you need to install the packagesmartmontools, which includes both the command and the daemonsmartdfor continuous monitoring. In Debian-based systems (Ubuntu, Linux Mint, etc.), the process is simple:
- Update the package index:
sudo apt update - Install the package:
sudo apt install smartmontools
In distributions of the RHEL family (CentOS, Fedora, Rocky Linux):
- For CentOS 7 / RHEL 6:
sudo yum install smartmontools - For Fedora 22 + or RHEL 8 + / CentOS Stream:
sudo dnf install smartmontools
After installation, check that your disk supports S.M.A.R.T. and that this functionality is enabled by running:
sudo smartctl -i /dev/sda
Search the lines at the exit:
- SMART support is:Indicates if the disk supports and has the S.M.A.R.T. monitoring activated
- SMART Enable:Confirms that the functionality is currently active.
If disabled, you can temporarily activate it withsudo smartctl -s on /dev/sda(although many disks have it enabled by default).
Rapid assessment of the health status of the disk
The most immediate use ofsmartctlis to obtain a general summary of the health of the device by means of the built-in self-diagnostic test:
sudo smartctl -H /dev/sda
The argument-H(or--health) executes rapid verification that analyses the critical attributes predefined by the manufacturer. The result will be one of the following:
- PASSED: All critical attributes are within the safety thresholds established by the manufacturer.
- FAILED: At least one critical attribute has exceeded its failure threshold, indicating an imminent risk of deterioration.
- UNKNOWN: The disk does not provide enough information for a conclusive evaluation (less common in modern hardware).
To obtain a more complete view of all the monitored attributes, use:
sudo smartctl -A /dev/sda
This command shows a detailed table where each row represents a specific S.M.A.R.T. attribute, including its current value, the worst recorded value, the failure threshold and if it is currently exceeding that threshold (marked asFAILING_NOW).
Critical S.M.A.R.T. Attributes that every administrator must know
Although disks can report dozens of attributes, certain indicators are particularly relevant to anticipate failures:
- Reallocated _ Sector _ Ct (ID 05): The number of sectors that have been marked as defective and reassigned to a reserve area is counted. A growing value suggests physical deterioration of the magnetic surface (in HDD) or flash cells (in SSD).
- Spin _ Retry _ Count (ID 06): In HDD, record how many times the disk has tried to rereach the full turning speed after an initial failure. High values may indicate problems in the axle engine or in the lubrication of bearings.
- Power _ On _ Hours (ID 09): Collects the total operating hours of the disk from its manufacture. Although it does not indicate direct failure, it helps to estimate the remaining service life based on use (e.g.: data centre disks usually have limits of 50,000 hours).
- Temperature _ Celsius (ID C2 or 194): It measures the internal temperature of the disk. Operating consistently above 50 ° C can accelerate wear; many manufacturers consider 60 ° C as an alert threshold.
- UDMA _ CRC _ Error _ Count (ID C7 or 199): Account for parity detection errors in data transfer via SATA interface. A sudden increase often indicates problems of wiring, loose connectors or electromagnetic interference.
- Wear _ Leveling _ Count (ID 173, SSD-specific): In solid state units, it reflects how uniformly writing operations have been distributed among memory cells. A high value indicates good wear management; low values suggest concentration of scriptures in specific areas.
It is important to note that the interpretation of these values should consider the manufacturer's specific specifications, as the alert thresholds may vary between product models and lines.
Implementation of active diagnostic tests
Beyond passive reading of attributes,smartctlallows to start tests that exercise the disk to reveal latent errors:
- Short test (
short): Conduct quick verification of critical disk areas (labels, partition tables, boot sectors). Ideal for routine reviews, it is usually completed in 2-5 minutes. - Extended test (
long): Undertake a full sector scan by sector, including user data areas. It may take 30 minutes to several hours depending on the capacity and speed of the disk, but it is the most effective for detecting hidden defective sectors. - Convection test (
offline): It runs in the background during periods of disk inactivity, without affecting normal performance. Useful for continuous monitoring without manual intervention.
To start any of these tests:
sudo smartctl -t [test_type] /dev/sda
Replace[test_type]withshort, longoroffline. After running the test, check the results with:
sudo smartctl -l selftest /dev/sda
The output will show the test number, its type, duration, status (e.g.:Completed without error, Interrupted, Failed: Read element occurred) and the percentage of completion if interrupted.
Implementation of proactive monitoring with smartd and cron
Use of daemonsmartd
Servicesmartd(included insmartmontools) monitors disks in real time and can run automatic actions when detecting off-threshold attributes. Its main configuration is in/etc/smartd.confwhere rules are defined as:
/dev/sda -a -o on -S on -s (S/../.././02|L/../../6/03) -m admin@empresa.com -M exec /usr/share/smartmontools/smartdrunner
This line indicates:
- -a: Enable all standard monitoring options
- -o on: Activates automatic offline monitoring
- -S on: Enable sector self-repair (if the disk supports it)
- -s: Daily short tests (S) at 02: 00 and long tests (L) on Saturdays at 03: 00
- -m: Send notifications by email
- -M exec: Run a custom script to critical events
After amendmentsmartd.conf, restart the service withsudo systemctl restart smartd(in systems with systemd).
Simple programming withcron
For environments where you prefer to avoid additional daemons, regular verifications can be programmed usingcron:
# Daily health check at 02: 30 AM
30 2 * * * root / usr / sbin / smartctl -H / dev / sda & & / usr / sbin / smartctl -A / dev / sda | grep -q «FAILED» & & mail -s «ALERTA: SMART failure in / dev / sda» admin @ empresa
This cron entry checks health every night and sends an alert only if a failure is detected, reducing the noise of unnecessary notifications.
Conclusion: Integrate smartctl into the data protection strategy
The commandsmartctltranscends its role as a simple diagnostic tool to become an essential component of any responsible Linux storage management policy. Its ability to provide early warnings of hardware deterioration allows it to move from a reactive (fix after failure) to a predictive (replace before interruption) approach. However, it is vital to remember that S.M.A.R.T. is not infallible: some catastrophic failures (such as physical blows or sudden electronics failures) can occur without notice. Therefore, the monitoring of disk health must always be complemented by:
- Regular security copies following rule 3-2-1
- System log monitoring for I / O errors
- Regular restoration tests for backups
- Understanding the specific limits of the hardware in use
When incorporatingsmartctlin daily maintenance routines and combined with good backup and surveillance practices, managers can significantly reduce the risk of unexpected data loss and maintain confidence in the availability of their critical systems.


