In a production Linux environment, hard drives do not fail gracefully. A mechanical HDD or modern NVMe SSD will often function perfectly at 9 AM, and then suffer a catastrophic mechanical failure or controller crash at 9:01 AM, instantly taking your databases offline and corrupting your data.
However, hard drives rarely die without a fight. Modern storage devices are equipped with a self-monitoring hardware system called S.M.A.R.T. (Self-Monitoring, Analysis, and Reporting Technology). Weeks before a drive actually dies, its internal microcontroller will begin quietly logging microscopic hardware errors, such as read retries, bad sector reallocations, and temperature spikes.
By default, Linux does not aggressively warn you about these underlying hardware errors. To predict an imminent drive failure before it destroys your data, you must manually query the S.M.A.R.T. chip using the smartctl command-line utility.
Step 1: Install Smartmontools
The smartctl utility is part of the smartmontools package, which is usually not installed by default on minimal server distributions.
- On Ubuntu/Debian:
sudo apt-get install smartmontools - On CentOS/RHEL/AlmaLinux:
sudo dnf install smartmontools
Step 2: Identify Your Hard Drives
Before you can interrogate a drive, you need to know its block device name.
- Run the command:
lsblk - Look for your primary disks (e.g.,
/dev/sdafor SATA drives, or/dev/nvme0n1for modern NVMe drives). Do not query the partitions (likesda1), query the root block device (sda).
Step 3: Run a Quick Health Check
If you just want a simple “Pass/Fail” answer from the drive’s internal firmware without reading through hundreds of lines of complex diagnostic data, you can run a targeted health query.
- Type the following command (assuming your drive is
sda):sudo smartctl -H /dev/sda - Press Enter.
You are looking for the line that says: SMART overall-health self-assessment test result: PASSED.
If this line says FAILED, the drive’s internal microcontroller has determined that mechanical failure is imminent within 24 hours. You must immediately halt all I/O operations and clone the disk.
Step 4: View the Detailed Attribute Table
If the drive says “PASSED,” you aren’t completely safe yet. The drive might be slowly accumulating bad sectors but hasn’t reached the critical failure threshold. To view the raw, detailed error logs, run the “all” command.
- Type the command:
sudo smartctl -a /dev/sda
Scroll down to the Vendor Specific SMART Attributes with Thresholds section. You will see a massive table.
Pay close attention to these three specific rows:
- 5 Reallocated_Sector_Ct: This is the most critical metric. When the drive discovers a physically broken microscopic sector on the platter, it quietly moves the data to a reserve sector. If the “RAW_VALUE” for this row is greater than zero and actively climbing over several weeks, the physical disk surface is actively degrading. The drive is dying.
- 197 Current_Pending_Sector: These are sectors that are currently unreadable, but the drive hasn’t successfully reallocated them yet because it is struggling to recover the corrupted data. A high number here indicates severe read errors.
- 199 UDMA_CRC_Error_Count: A high number here rarely means the drive itself is dying; it almost always indicates a physically damaged SATA cable connecting the drive to the motherboard, resulting in corrupted data transfer.
By running smartctl -a once a month, you can easily spot a failing drive weeks before it actually flatlines.