Tutoriel Linux

Smartctl under Linux: checking a disk before it fails

Débutant5 min de lecture
À retenirLinux n'est pas réservé aux experts. Le bon point de départ : une distribution accessible, une sauvegarde propre et quelques commandes comprises.

A disk can still respond to commands while accumulating unstable sectors, media errors, or advanced wear. If you wait for the first I/O error to check its status, the backup process can already become complicated.

smartctlprovided by the package smartmontoolsIt reads SMART information from SATA, SAS, and NVMe drives. I use it to confirm a doubt, but never as a guarantee: a status PASSED This does not prevent a sudden failure. The goal is to cross-reference the overall state, useful counters, a self-test, and kernel logs before making a decision.

Tux inspects the SMART status of a hard drive before it fails.
Smartctl helps cross-reference SMART status, media errors, and self-tests before backing up or replacing a disk.

Identify the disk before launching smartctl

Do not assume that the disc in question is /dev/sdaIts name may change after a restart or the addition of a device. View models, serial numbers, and connection types:

lsblk -d -o NAME,SIZE,MODEL,SERIAL,TRAN,TYPE
lsblk -o NAME,SIZE,FSTYPE,MOUNTPOINTS,MODEL,SERIAL

The first command lists the physical block devices. The second allows you to link a disk to its partitions and mount points. If several models have the same capacity, the serial number prevents a costly mistake. The guide on lsblk under Linux details this identification before assembly or formatting.

Once Once installed, also ask the tool which devices it can open:

sudo smartctl --scan-open

Work on the entire disk, for example /dev/sda Or /dev/nvme0, not on a score like /dev/sda1.

Install smartmontools and verify SMART support

On Debian or Ubuntu:

sudo apt update
sudo apt install smartmontools

On Fedora, Rocky Linux or AlmaLinux:

sudo dnf install smartmontools

On Arch Linux:

sudo pacman -S smartmontools

Next, check the disk identity and SMART availability:

sudo smartctl -i /dev/sda

You need to find the model and serial number seen with lsblkOn a USB-to-SATA enclosure, SMART can be hidden by the bridge. This variant works with certain adapters:

sudo smartctl -a -d sat /dev/sdb

Do not force a device type at random. Check the result of --scan-open and the documentation for the RAID enclosure or controller. Some controllers require a specific option to access each physical disk.

Read the overall picture without trusting a single word

Start with the overall health test:

sudo smartctl -H /dev/sda

A result This means the disk has not crossed the failure threshold defined by its manufacturer. It does not mean it is new, error-free, or incapable of failing tomorrow. A result FAILED requires immediate backup and replacement, not a new series of tests for reassurance.

Then display the full report:

sudo smartctl -a /dev/sda

First, verify that the model, serial number, and capacity match the target drive. Then, check the temperature, operating hours, error log, and self-test results. The option -x provides more details when -has is not enough:

sudo smartctl -x /dev/sda

Identify the metrics that change the decision

On a SATA drive, pay particular attention to Reallocated_Sector_Ct, Current_Pending_Sector And Offline Uncorrectable

UDMA_CRC_Error_Count This often points to the SATA connection: cable, connector, power supply, or controller. If this counter is rising, check the connections and then reread the report. Don’t confuse a transmission error with a bad sector.

On an NVMe SSD, look Critical Warning, Available Spare, Percentage Used And Media and Data Integrity ErrorsA reserve below the threshold, a critical warning, or increasing media errors should trigger action. represents an estimate of endurance consumed, not a precise countdown.

Names, thresholds, and raw values ​​vary by manufacturer. Always compare several readings from the same drive. Copying a raw value from a different model can easily lead to a misdiagnosis.

Run a short test and then retrieve its result.

sudo smartctl -t short /dev/sda

smartctl

sudo smartctl -l selftest /dev/sda
sudo smartctl -a /dev/sda

The result should appear as completed without errors. An interrupted test can originate from a shutdown, sleep mode, or another test command. A failed test, combined with unstable sectors or kernel errors, reinforces the decision to replace the disk.

The long test with smartctl -t long It covers a larger area, but it takes much longer. Don’t use it as the first action on a disk that’s already failing. In that case, recover any data that’s still readable before adding more hours of activity.

Cross-referencing SMART with kernel errors

SMART does not replace Linux logs. Look for binding errors, resets, and I/O errors during the current boot process:

sudo journalctl -k -b -p warning..alert --no-pager

The tutorial on dmesg and kernel messages It helps to distinguish a failing hard drive from an unstable USB cable, controller, or power supply. A saturation reading taken with iostat is also not proof of physical failure: it describes a load, not the health of the storage medium.

Back up your data before repairing the file system

If SMART fails, if media errors increase, or if the kernel reports input/output errors, reduce writes and back up important data. On a remote server, verify that the copy is usable before any reboot.

Don’t throw to test the equipment. fsck It works on file system consistency and can put significant strain on already fragile hardware. The guide on fsck under Linux begins intentionally with identification, disassembly and a non-writing inspection.

For a NAS or server, keep dated SMART reports and monitor their evolution. The guide Linux for a home NAS It’s also worth remembering that a RAID array doesn’t replace a backup. A disk can be replaced, but copies of your data cannot.

There smartctl manual page documents the options, device types, and self-tests. examples from the smartmontools project show the main SATA and NVMe reports. Keep this order: identify the correct drive, read the full status, run a short test if the drive remains stable, then back up or replace as soon as the signals converge.

sudo apt update && sudo apt upgrade