Configure S.M.A.R.T. monitoring on Linux by editing the /etc/smartd.conf file to define device-specific directives, then restart the smartd service. This setup enables automated health checks and email alerts for impending drive failures, ensuring data integrity without manual intervention.
Prerequisites and Installation
Before modifying configuration files, ensure the necessary software is installed. On modern Red Hat-based distributions, usednf rather than the legacy yum command. Install the daemon using:
sudo dnf install smartmontools
On Debian or Ubuntu systems, the package name remains smartmontools. Verify installation by checking the version:
smartctl --version
Ensure the smartd service is enabled to start at boot. Use your system's init system to manage this:
sudo systemctl enable smartd
sudo systemctl start smartd
If you are running a dual-boot environment, note that Windows may lock drives in hibernation mode, preventing Linux from accessing S.M.A.R.T. data. Ensure Windows fast startup is disabled if you monitor those drives from Linux. See our guide on Double Booting Windows 11 and Ubuntu 20.04 LTS on a New HDD for more context on managing shared storage.
Identifying Drives
List all detected devices with their S.M.A.R.T. capabilities. The-a flag provides comprehensive output.
sudo smartctl -a /dev/sda
Look for the "SMART support" lines. If it says "Unavailable - device does not support SMART," the drive may lack hardware support or be behind a RAID controller that requires specific driver modules. For NVMe drives, use /dev/nvme0n1 instead of /dev/sdX.
Configuring /etc/smartd.conf
The core configuration happens in/etc/smartd.conf. Each line defines a directive for a specific device. The general syntax is:
/dev/device DEVICE_OPTIONS [-o] [-S] [-m [email protected]]
Key options include:
- -a: Enable all standard checks (equivalent to many individual flags).
- -o: Enable automatic offline tests.
- -S: Save autosave attributes.
- -m: Send email alerts to the specified address.
- -M: Specify the mail program (usually left default).
/dev/sda -a -o -S -s (L|../../..|02|00) -m [email protected]
This configures sda to run all checks, enable offline saving, schedule long self-tests every Sunday at midnight, and email [email protected] on failure.
For NVMe drives, the syntax is similar but uses the NVMe device path:
/dev/nvme0n1 -a -m [email protected]
Always test your configuration syntax before restarting the service. Use the -d debug flag to simulate execution without sending emails:
sudo smartd -d /etc/smartd.conf
Check for syntax errors in the output. If no errors appear, proceed to restart.
Handling Multiple Drives
Repeat the line for each monitored drive. Use different email addresses or groups if needed. Avoid combining multiple devices into one line unless they share identical policies, as this complicates troubleshooting. See our article on Check Hard Drive Status for Personal Photos in Linux for deeper diagnostics on individual drive health metrics.Restarting and Verifying
Apply changes by restarting the daemon:sudo systemctl restart smartd
Verify the service is running:
sudo systemctl status smartd
Check logs for successful initialization:
sudo journalctl -u smartd
Look for lines indicating devices were opened and configured. If you receive errors about permission denied, ensure your user has access to the device nodes, though smartd typically runs as root.
Email Testing
To confirm email alerts work, trigger a simulated failure. Some drives support a "self-test" that can be forced. However, caution is advised; do not force tests on production drives during peak hours. Instead, check the/var/log/syslog or /var/log/messages for any alert patterns.
If emails fail, verify your MTA (Mail Transfer Agent) like Postfix or Sendmail is configured correctly. smartd relies on the system's local mail delivery.
Troubleshooting Common Issues
- Device not found: Check
dmesg | grep sdto ensure the kernel recognizes the drive. - Permission errors: Ensure
smartdhas read access to/dev/sdX. Usually, root privileges suffice. - No alerts received: Verify the email address is correct and the MTA is operational. Test with a simple
echo "test" | mail -s "Test" [email protected]. - High CPU usage: Rare, but excessive polling intervals can cause load. Adjust the
-sschedule if needed.
Frequently Asked Questions
How do I check S.M.A.R.T. status manually?
Use the smartctl -a /dev/sdX command to view detailed health information. Look for the "Overall-health" line, which should state "PASSED" if no critical errors exist. This tool provides real-time data independent of the background daemon.
Can I monitor NVMe drives with smartd?
Yes, smartd supports NVMe devices using the /dev/nvmeXnY naming convention. Configure them in /etc/smartd.conf just like SATA drives, using the -a flag for comprehensive monitoring. Note that some older versions of smartmontools may require updates for full NVMe feature support.
Why am I not receiving email alerts?
Most often, the issue lies with the local Mail Transfer Agent (MTA) configuration rather than smartd itself. Ensure services like Postfix or Sendmail are running and properly configured to send local mail. Test email functionality independently using command-line tools before blaming the monitoring daemon.
Does S.M.A.R.T. protect against ransomware?
No, S.M.A.R.T. monitors physical hardware health and firmware errors, not logical data corruption or malware. Ransomware encrypts files, which does not trigger hardware failure alerts. Always maintain separate, offline backups to protect against cyber threats, regardless of drive health status.
How do I exclude a specific drive from monitoring?
Simply omit the drive from /etc/smartd.conf. Alternatively, comment out the line by adding a # at the beginning. Do not delete the line if you plan to re-enable monitoring later. Restart the smartd service after making changes to apply exclusions.