Skip to content
Servers

How to Check Disk Health on a Linux Server With smartctl

In this article12 sections

To check disk health on a Linux server, install smartmontools and run sudo smartctl -a on each drive. Every disk keeps its own record of errors and wear, called SMART data, and smartctl reads it. Do not stop at the line that says PASSED: a drive reports that until it is very close to failing. The numbers that actually warn you are a handful of counters, such as reallocated and pending sectors on a SATA drive, or percentage used and media errors on an NVMe drive. This guide shows which ones to read, what value is a problem, and how to be told automatically.

It applies to dedicated servers and any machine with real disks, running Ubuntu, Debian or a similar distribution. It does not apply to a VPS, for a reason explained near the end.

Step 1: Install the tool and list the drives

sudo apt update && sudo apt install -y smartmontools
lsblk -d -o NAME,MODEL,SIZE,ROTA,TRAN
sudo smartctl --scan

lsblk shows each physical drive: ROTA 1 is a spinning hard disk, ROTA 0 is an SSD, and TRAN nvme is an NVMe drive. smartctl --scan lists the device names to use in the commands below, such as /dev/sda or /dev/nvme0.

Step 2: The quick verdict

sudo smartctl -H /dev/sda
SMART overall-health self-assessment test result: PASSED

FAILED means replace the drive now. PASSED means only that no value has crossed the manufacturer’s last-resort threshold. Plenty of drives die while still reporting it, so read on.

Step 3: Read a SATA hard disk or SSD

sudo smartctl -A /dev/sda

This prints a table of attributes. Ignore the VALUE, WORST and THRESH columns at first and look at RAW_VALUE, the last column, for these six:

ID Attribute Healthy What a higher number means
5 Reallocated_Sector_Ct 0 Bad areas the drive has already swapped out. Any number that keeps growing means the drive is failing
197 Current_Pending_Sector 0 Areas the drive could not read and is waiting to retry. The strongest early warning
198 Offline_Uncorrectable 0 Areas that could not be read or repaired. Data has probably been lost there
187 Reported_Uncorrect 0 Read errors passed up to the operating system
199 UDMA_CRC_Error_Count 0 or not rising Errors on the cable or connector, not the disk itself
9 Power_On_Hours Any Age. 40,000 hours is about four and a half years of continuous use

The rule is simple: for attributes 5, 187, 197 and 198, zero is healthy, a small steady number is a drive to watch weekly, and a number that rises between checks is a drive to replace. Write the values down with the date, because the trend matters more than any single reading.

SSDs add a wear figure, named differently by each maker: Wear_Leveling_Count, Media_Wearout_Indicator or Percent_Lifetime_Remain. Its VALUE column normally counts down from 100 towards 0 as the drive wears.

Step 4: Read an NVMe drive

NVMe drives report a shorter, clearer list:

sudo smartctl -a /dev/nvme0
Line Healthy What it means
Critical Warning 0x00 Anything else is the drive itself reporting a fault
Available Spare Well above the threshold shown on the next line Reserve blocks left for replacing worn ones
Percentage Used Below 100% Wear against the maker’s rated lifetime. It can pass 100% and keep working, but plan a replacement
Media and Data Integrity Errors 0 Data the drive could not return correctly. Any value above zero is serious
Unsafe Shutdowns Low and not rising Power lost without a clean shutdown
Temperature Below about 70 °C Sustained heat shortens the drive’s life

Step 5: Run a self-test

The counters only record problems the drive has already met. A self-test makes it read its whole surface and find the ones it has not met yet. The server stays in use while it runs.

sudo smartctl -t short /dev/sda     # about 2 minutes
sudo smartctl -t long /dev/sda      # 1 to several hours on a hard disk

The command returns immediately and prints when the test will finish. Read the result afterwards:

sudo smartctl -l selftest /dev/sda
Num  Test_Description    Status                  Remaining  LifeTime(hours)
# 1  Extended offline    Completed without error       00%     31412
# 2  Short offline       Completed without error       00%     31398

Completed: read failure with an address in the last column means the drive has unreadable areas, whatever the overall verdict says.

Step 6: Servers with RAID

Software RAID (Linux mdadm): check each member disk with smartctl as above, and check the array itself:

cat /proc/mdstat

[UU] means both disks of a mirror are active. [U_] means one has dropped out and the array is running without protection.

Hardware RAID: the operating system sees one virtual disk, and a plain smartctl command reports nothing useful. Ask for each physical disk behind the controller by number instead:

sudo smartctl -a -d megaraid,0 /dev/sda
sudo smartctl -a -d megaraid,1 /dev/sda

megaraid covers the common LSI, Broadcom and Dell PERC controllers. sudo smartctl --scan suggests the right -d option for the controller it finds.

Step 7: Be told automatically

The package includes a service, smartd, that watches the drives and logs or emails when something changes. Replace the active line in /etc/smartd.conf with:

DEVICESCAN -a -o on -S on -s (S/../.././02|L/../../6/03) -m root -M exec /usr/share/smartmontools/smartd-runner

That monitors every drive, runs a short test daily at 02:00 and a long test every Saturday at 03:00, and reports problems to root’s mail. Then restart it and check that it found your drives:

sudo systemctl restart smartmontools
sudo journalctl -u smartmontools --since "5 minutes ago" | grep -i "monitoring"

If the server cannot send mail, the warnings still appear in the system log. Search it weekly with sudo journalctl -u smartmontools -p warning, or have your monitoring tool watch for them.

What to do when a number is bad

  1. Back up first. A drive with pending or reallocated sectors can fail completely during the next heavy read. Copy the data that matters before you run a long test or anything else.
  2. Save the evidence. sudo smartctl -x /dev/sda > sda-smart.txt writes the full report to a file.
  3. Ask for a replacement. On a rented server the hardware belongs to the provider. Open a ticket, attach the report, and say which drive by its serial number, shown at the top of the output.
  4. Rebuild, then test the new drive. After the swap, let the RAID array rebuild fully, and run a long test on the new disk.

Warning. RAID is not a backup. A mirror protects you from one disk failing, and it faithfully copies a deleted file or a corrupted database to both disks. Keep backups on a different machine.

Why this does not work on a VPS

A VPS has no physical disk of its own. What it sees is a virtual disk carved out of the host’s storage, which has no SMART data to report, so smartctl answers that the device lacks SMART capability. The physical drives underneath are the provider’s to monitor and replace. On a VPS, your part is backups, covered in how to back up MariaDB and PostgreSQL on a VPS.

Common mistakes to avoid

  • Trusting PASSED. Read the counters.
  • Checking once. One reading tells you little. The change between two readings tells you everything.
  • Running a long test on a failing drive before backing it up. The test is exactly the kind of work that finishes off a weak disk.
  • Blaming the disk for CRC errors. Attribute 199 points to the cable or backplane.
  • Forgetting the second disk. In a mirror, check both. They are usually the same age and model, and they tend to fail close together.

Disks on a SiteHarbour dedicated server

A SiteHarbour dedicated server gives you the whole machine with full root access, so every command in this guide works as written, and the IPMI console is there if you ever need to reach the server outside the operating system. Configurations range from single SSDs to dual NVMe drives, and our engineers are available around the clock: send us the smartctl report when a counter starts to move.

If a failing disk leaves the server unreachable over SSH, you can still reach it through the out-of-band console. How to recover a locked-out server with IPMI explains how to use it safely, step by step.

Frequently asked questions

How often should I check?

Let smartd watch continuously, and look at the counters yourself once a month. After any warning, check weekly until the drive is replaced or the number has stopped changing.

Is one reallocated sector a reason to replace a drive?

Not by itself. A few that never increase can stay that way for years. Replace the drive when the number grows, or when pending sectors appear alongside it.

Does running a self-test slow the server?

Slightly. The drive gives priority to normal work and tests in the gaps, which is why a long test can take hours on a busy server.

How long do server drives last?

Many run five years or more, but failures cluster in the first months and again after about four years. Age is a reason to watch more closely, not a reason to replace.

Can SMART predict every failure?

No. A share of drives fail with no warning at all, from a fault in the electronics rather than the surface. That is why SMART monitoring goes together with RAID and backups, never instead of them.

The short version: PASSED is not enough. On SATA drives watch attributes 5, 187, 197 and 198; on NVMe watch critical warning, percentage used and media errors. Let smartd run the tests, and back up before you touch a drive whose numbers are rising.

Share this guide