cheat-sheets

smartctl

smartctl (from smartmontools) reads and tests a disk’s SMART data, and smartd watches it in the background and emails or notifies you. Use it to catch a failing drive before it dies. SMART is a hint, not a guarantee, so keep backups regardless. For the hardware overview see Hardware Inspection.

Documentation: smartmontools, smartctl man page (this mirror is smartmontools 5.43 from 2012, so NVMe and newer options are not covered here)

Install #

bash
sudo apt install smartmontools

Read Health #

COMMANDDESCRIPTION
sudo smartctl --scanList devices smartctl can see
sudo smartctl -i /dev/sdXModel, serial, firmware, capacity, SMART enabled
sudo smartctl -H /dev/sdXOverall health verdict (PASSED or FAILED)
sudo smartctl -A /dev/sdXAttribute table (ATA drives)
sudo smartctl -a /dev/sdXEverything ATA: health, info, capabilities, attributes, error and self-test logs
sudo smartctl -x /dev/sdXExtended output, including more logs
sudo smartctl -c /dev/sdXCapabilities and self-test durations
sudo smartctl -l error /dev/sdXThe most recent errors
sudo smartctl -l selftest /dev/sdXSelf-test history

A failing -H means the drive has failed or predicts failure within 24 hours. A passing -H does not mean the drive is healthy, so read the attributes and logs too. An attribute marked “Pre-fail” does not mean the disk is about to fail. The normalised value is compared with the threshold, and at or below it the attribute has failed.

Self-tests #

COMMANDDESCRIPTION
sudo smartctl -t short /dev/sdXShort test, a few minutes
sudo smartctl -t long /dev/sdXFull surface scan, can take hours
sudo smartctl -t conveyance /dev/sdXCheck for shipping damage
sudo smartctl -c /dev/sdXShows how long each test takes

Run a test, wait for the stated duration, then read the result with -l selftest. Tests run on the drive while it stays usable.

Attributes Worth Watching #

IDNAMEWHY IT MATTERS
5Reallocated sectorsBad sectors the drive has remapped. A rising count is a warning
187Reported uncorrectable errorsRead errors the drive could not correct
188Command timeoutOperations that timed out, often cabling or power
197Current pending sectorsSectors waiting to be remapped. Non-zero is a warning
198Offline uncorrectableSectors that failed during offline scans
199UDMA CRC error countUsually a bad SATA cable or connector

The IDs and meanings are widely used, but were not confirmed from the man page in this pass. Vendors differ, so watch for change over time rather than one reading.

Device Types #

SITUATIONOPTION
Plain SATA or SAS on LinuxUsually automatic
USB enclosure-d sat (some bridges need -d sat or -d usbjmicron, -d usbcypress, -d usbsunplus)
Behind a MegaRAID controller-d megaraid,N where N is 0 to 127, e.g. smartctl -a -d megaraid,2 /dev/sda
NVMesmartctl -a /dev/nvme0 or nvme smart-log /dev/nvme0 (nvme-cli). Not checked in this pass

Use -n standby to skip a sleeping disk, and give -d as well or the disk may spin up.

smartd #

smartd polls every 30 minutes by default. Generate a starting config from a scan:

bash
sudo smartctl --scan-open -- -a -W 4,45,50 -m admin@example.com | sudo tee /etc/smartd.conf

A typical hand-written line (check smartd.conf(5) for the exact syntax on your version):

text
DEVICESCAN -a -o on -S on -s (S/../.././02|L/../../6/03) -m admin@example.com

That monitors all disks, runs a short test daily at 02:00 and a long test on Saturdays at 03:00, and emails on problems.

COMMANDDESCRIPTION
sudo smartd -q onecheckCheck once and exit, to test the config
sudo smartd -q showtestsShow the self-test schedule
sudo systemctl restart smartdReload after editing (service name is smartd or smartmontools by distro)

The service name and the schedule syntax are from experience, not the man page read here. Monitoring tools such as Beszel can also read SMART data.

See Also #

Search all sheets

Tip: / or Ctrl/Cmd+K to open, Esc to close.