Guides 11792 Published by

This guide explains how to keep hard drives healthy by installing and configuring smartctl on both CentOS 8 / RHEL 8 and Ubuntu 20.04, showing the steps needed to pull in the required repositories, install the package, and verify the version. On CentOS systems it walks through enabling EPEL, using dnf to grab smartmontools, identifying disks with lsblk, running a quick SMART report, and then creating a small shell script that logs health status and optionally emails alerts while scheduling it with cron for daily execution. For Ubuntu users it mirrors the installation process with apt, demonstrates a simple single‑line health check, and then sets up a modern systemd service and timer pair that runs smartctl each day, letting you query the timer status whenever you need to see when checks occurred. The article closes by sharing a real‑world incident where an abrupt power loss caused a sudden spike in reallocated sectors, illustrating how daily monitoring could have saved data, and it encourages readers to stick scripts or timers in place to avoid surprise failures.



Install and Configure Smartctl on CentOS 8 / RHEL 8 and Ubuntu 20.04 – Keep Your Drives Alive

If your server or workstation has a hard drive that’s been around since 2014, you’ll want to know when it starts chewing up data. Installing smartctl (the command‑line tool from smartmontools) gives you a cheap, reliable way to peek at those hidden health metrics and set up alerts before the disk finally dies.

Install Smartctl on CentOS 8 / RHEL 8
1. Make sure EPEL is enabled

EPEL supplies many extra packages that aren’t in the default repos. Without it you’ll get a “package not found” error when you try to install smartmontools.

sudo dnf install -y epel-release

The epel-release package pulls in the repository metadata, letting DNF find smartmontools.

2. Install smartmontools
sudo dnf install -y smartmontools

The -y flag just keeps the installer from asking for confirmation on every prompt – handy when you’re scripting this.

3. Verify the installation
smartctl --version

You should see something like “smartmontools 7.1” in the output. If it prints an error, double‑check that EPEL is still enabled and try again.

Configure Smartctl on CentOS 8 / RHEL 8
4. Identify your disks
lsblk -dno NAME,SIZE,MODEL

Pick the device names (/dev/sda, /dev/nvme0n1, etc.) you want to monitor.

5. Run a quick health check (optional but handy)
sudo smartctl -a /dev/sda | less

Scrolling through the raw data shows all the SMART attributes. You’ll often spot an attribute like Reallocated_Sector_Ct that has begun creeping up after a bad driver update.

6. Set up a daily cron job to auto‑check

Create a script /usr/local/bin/smart-check.sh:

#!/bin/bash
DEVICE="/dev/sda"
OUTPUT=$(smartctl -H "$DEVICE")
echo "$(date '+%Y-%m-%d %H:%M:%S'): $OUTPUT" >> /var/log/smart-check.log

# If the disk reports a failure, email yourself
if echo "$OUTPUT" | grep -q "FAILED"; then
    mail -s "SMART ALERT: $DEVICE failed" you@example.com < /dev/null
fi

Make it executable:

sudo chmod +x /usr/local/bin/smart-check.sh

Add a cron entry to run it daily at 2 am:

echo "0 2   * root /usr/local/bin/smart-check.sh" | sudo tee /etc/cron.d/smart-check

A cron job keeps the check from becoming an after‑thought. The email guard is a simple, reliable alert.

Install Smartctl on Ubuntu 20.04
1. Update package lists
sudo apt update
2. Install smartmontools
sudo apt install -y smartmontools

The -y flag works the same as in CentOS.

3. Verify installation
smartctl --version

You should see “smartmontools 7.1” or later.

Configure Smartctl on Ubuntu 20.04
4. Find your disks

Same lsblk command works:

lsblk -dno NAME,SIZE,MODEL
5. Quick health check
sudo smartctl -H /dev/sda

The output is a single line: “SMART overall-health self-assessment test result: PASSED” or “FAILED”. If you see Reallocated_Sector_Ct spiking after a sudden power loss, the disk might be in trouble.

6. Automate with systemd timer (modern way)

Create /etc/systemd/system/smartcheck.service:

[Unit]
Description=Smartctl health check

[Service]
Type=oneshot
ExecStart=/usr/bin/smartctl -H /dev/sda

Create a timer file /etc/systemd/system/smartcheck.timer:

[Unit]
Description=Run smartctl once per day

[Timer]
OnCalendar=daily
Persistent=true

[Install]
WantedBy=timers.target

Reload systemd, enable and start the timer:

sudo systemctl daemon-reload
sudo systemctl enable --now smartcheck.timer

Why a timer? It’s cleaner than cron, respects shutdown ordering, and you can see status with systemctl list-timers.

A Real‑World Observation

I once had a server that crashed after an abrupt power outage. The next day the SMART attributes on /dev/sda were screaming: “Reallocated_Sector_Ct” was up by 300 sectors in just a few hours. If I’d had smartctl running daily, I would have seen the warning before the data loss happened.

Wrap‑Up

Now you’ve got Smartctl installed on both major distros and a routine that will let you know when your disks start acting up. Stick the script or timer in place, keep an eye on /var/log/smart-check.log, and you’ll save yourself from surprise failures. Happy monitoring!