Context & Why: The Problem of Silent Disk Degradation
Few operational emergencies match the chaos of an unannounced storage failure. A server suddenly drops into a read-only filesystem state. Application threads pile up in uninterruptible sleep (the dreaded D state). Worse, database transactions corrupt halfway through disk writes, leaving you with scrambled tables and an angry team.
Modern drives rarely die without dropping hints first. Long before a motor freezes or a NAND controller locks up completely, storage devices accumulate warning signs. You will see bad blocks, reallocated sectors, and CRC transmission errors from loose or degraded SATA cables.
Heat spikes above 55°C also take their toll. Unfortunately, the standard Linux kernel remains quiet while a drive remaps bad sectors in the background. The OS simply trusts the drive controller to handle internal wear—right up until read/write I/O operations block completely.
Active hardware telemetry bridges this gap. S.M.A.R.T. (Self-Monitoring, Analysis and Reporting Technology) lives inside nearly every modern drive controller. On Linux, smartmontools gives you direct access to this hardware data through two core utilities:
- smartctl: A command-line utility for manual spot checks, on-demand hardware self-tests, and vendor attribute dumps.
- smartd: A lightweight background daemon (typically using under 15MB of RAM) that polls drive health, runs scheduled self-tests, and triggers email warnings when critical thresholds drop.
On a busy Ubuntu database host with dual SATA SSDs, catching 24 reallocated sectors on /dev/sdb early let me swap the drive during a planned 15-minute maintenance window instead of scrambling through an unexpected 3:00 AM outage.
Installation: Setting Up Smartmontools and Mail Delivery
You need the core diagnostic tools and a minimal mail transfer utility so the daemon can dispatch outbound failure alerts.
1. Install Packages on Debian/Ubuntu and RHEL Systems
On Debian and Ubuntu, pull down smartmontools alongside mailutils (or bsd-mailx):
sudo apt update
sudo apt install smartmontools mailutils -y
For RHEL, Rocky Linux, or AlmaLinux, install the packages with dnf:
sudo dnf install smartmontools mailx -y
2. Discover and Inspect Connected Storage Devices
Scan for physical disks before modifying configuration files:
sudo smartctl --scan
You will see a list of detected drives along with their bus interfaces (SATA, NVMe, or SCSI):
/dev/sda -d scsi # /dev/sda, SCSI device
/dev/nvme0 -d nvme # /dev/nvme0, NVM Express device
Next, confirm whether S.M.A.R.T. monitoring is active on your target device:
sudo smartctl -i /dev/sda
Look at the bottom lines of the output. If S.M.A.R.T. support shows as available but disabled, turn it on:
sudo smartctl -s on /dev/sda
Configuration: Polling, Self-Tests, and Email Notifications
Manual checks work fine for one-off troubleshooting, but human memory is unreliable. True server resilience requires smartd to monitor health continuously.
1. Ad-hoc Drive Assessment with smartctl
Run a quick sanity check to view overall drive health:
sudo smartctl -H /dev/sda
A PASSED result is reassuring, but it does not tell the whole story. Drives with hundreds of pending bad blocks can still display a passing grade if vendor error thresholds have not yet tripped. Dig into the raw attribute values to see what is really happening:
sudo smartctl -A /dev/sda
On SATA HDDs and SSDs, watch these key counters:
- ID 5 (Reallocated_Sector_Ct): Raw values above
0mean damaged sectors have already been moved to spare reserve space. A value jumping from 0 to 50 within days signals that the media surface is failing. - ID 187 (Reported_Uncorrect): Read errors that hardware ECC could not recover. Any number greater than zero warrants immediate data backups.
- ID 197 (Current_Pending_Sector): Unstable sectors waiting to be remapped. If writes fail here, data loss follows shortly after.
- ID 199 (UDMA_CRC_Error_Count): Usually points to a crimped, oxidised, or loose SATA data cable rather than a dying drive. Try reseating or swapping the cable first.
NVMe drives format their telemetry differently. Query them with:
sudo smartctl -a /dev/nvme0n1
Keep a close eye on Available Spare (replace the drive if this dips below 10%) and Percentage Used to plan hardware refreshes before write endurance runs out.
2. Configuring the smartd Daemon
Open the primary daemon configuration file:
sudo nano /etc/smartd.conf
Most Linux distributions enable an unconfigured catch-all line by default. Comment out DEVICESCAN so you can define explicit monitoring rules for your production disks:
# Comment out default catch-all line:
# DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner
Add tailored monitoring directives at the bottom of the file:
# Monitor /dev/sda (SATA SSD/HDD)
/dev/sda -a -o on -S on \
-s (S/../.././02|L/../../6/03) \
-W 4,45,55 \
-m [email protected] -M test
Here is what these flags instruct smartd to do:
-a: Monitors all standard S.M.A.R.T. health attributes.-o on: Enables automatic offline background data collection every 4 hours on supported hardware.-S on: Automatically saves attribute states across power cycles.-s (S/../.././02|L/../../6/03): Runs a short self-test (S) daily at 2:00 AM, and an extended self-test (L) every Saturday at 3:00 AM.-W 4,45,55: Tracks operating temperatures. Logs changes of 4°C, issues a warning at 45°C, and triggers a critical alert if the disk hits 55°C.-m [email protected]: The destination inbox for alerts.-M test: Fires a sample email every timesmartdrestarts, proving your mail server actually routes alerts.
3. Enable the Daemon Service
On Debian and older Ubuntu releases, ensure the daemon startup flag is active in /etc/default/smartmontools:
sudo sed -i 's/^#start_smartd=yes/start_smartd=yes/' /etc/default/smartmontools
Activate and launch the systemd service:
sudo systemctl enable --now smartd
Verification & Monitoring: Confirming Delivery and Test Runs
An unverified monitoring setup gives a false sense of security. Always confirm that notification emails arrive and that scheduled hardware self-tests actually complete.
1. Verify the Test Email
Thanks to the -M test parameter in /etc/smartd.conf, the daemon sends an email the moment the service spins up. Check your system journal to verify transmission:
sudo journalctl -u smartd -e
Look for lines confirming delivery to your local MTA or relay:
smartd[2412]: Executing test of <mail> to [email protected]...
smartd[2412]: Test of <mail> to [email protected]: successful
Check your inbox (and spam folder) or inspect the local mail queue with mailq. Once you verify that messages arrive reliably, remove the -M test flag from /etc/smartd.conf and reload the daemon:
# Edit /etc/smartd.conf to remove "-M test", then run:
sudo systemctl reload smartd
2. Execute and Review a Manual Self-Test
Test the hardware immediately rather than waiting for the weekend schedule. Fire off a manual short self-test on /dev/sda:
sudo smartctl -t short /dev/sda
Short tests usually take 60 to 120 seconds. Extended tests on large 12TB mechanical drives can take upwards of 18 to 24 hours. Wait two minutes, then inspect the drive’s self-test log:
sudo smartctl -l selftest /dev/sda
Examine the newest entry at the top of the table:
Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error
# 1 Short offline Completed without error 00% 14280 -
Completed without error means the controller detected no surface flaws or mechanical issues. If the status reports an uncorrectable read failure, copy the LBA_of_first_error address and start your drive replacement plan before the disk goes read-only.
3. Routine Maintenance Commands
Keep these commands in your sysadmin toolkit for day-to-day operations:
systemctl status smartd: Verifies that the background daemon is healthy and running.smartctl -l error /dev/sda: Prints the internal ATA error log, tracking hardware handshake resets, command timeouts, and bus glitches.smartctl -X /dev/sda: Aborts a running self-test immediately if your applications suddenly need peak disk I/O throughput.
Automated hardware checks with smartmontools turn unexpected drive failures into routine, scheduled maintenance.

