NVMe drives usually do not give much warning before they fail completely. I use nvme-cli on my Arch laptops and Proxmox machines to check the important values before a drive turns into an unplanned restore job.
This is not a replacement for backups. My important machines still have regular Restic backups, including immutable copies as described in my Restic Backups to Backblaze B2 with Object Lock post. SMART values can help to replace a drive early, but they cannot protect against accidental deletes, filesystem damage or a dead controller.
Installing nvme-cli and finding the drive
On Arch Linux, nvme-cli is available directly in the repositories:
$ sudo pacman -S nvme-cli jq
On Gentoo I install the sys-apps/nvme-cli package. jq is only needed for the small health-report script later.
First list all NVMe devices:
$ sudo nvme list
Node SN Model Namespace Usage Format FW Rev
---------------- -------------------- ---------------------------------------- --------- -------------------------- ---------------- --------
/dev/nvme0n1 ... NVMe SSD 1 512.11 GB / 512.11 GB 512 B + 0 B ...
The namespace is usually /dev/nvme0n1, while the controller device is /dev/nvme0. For SMART logs, self-tests and firmware related commands I normally use the controller device.
Do not confuse an NVMe controller such as
/dev/nvme0with its namespace/dev/nvme0n1. Mostnvme-clicommands work with both, but using the controller avoids surprises with multi-namespace drives.
Reading NVMe SMART data
The basic command is simple:
$ sudo nvme smart-log /dev/nvme0
Smart Log for NVME device:nvme0 namespace-id:ffffffff
critical_warning : 0
temperature : 39 °C
available_spare : 100%
available_spare_threshold : 10%
percentage_used : 4%
data_units_read : ...
data_units_written : ...
media_errors : 0
num_err_log_entries : 0
I mostly look at these values:
critical_warning: Must be0. Any non-zero value needs attention.temperature: Normal desktop and server values depend on airflow, but a permanently hot SSD is not great. Around 70 °C or more under normal load is worth investigating.available_spare: Remaining reserve flash blocks. It should stay aboveavailable_spare_threshold.percentage_used: Vendor estimate of flash wear.100%means the rated endurance has been consumed, not necessarily that the drive dies immediately.media_errors: Unrecoverable media errors. A non-zero value is a warning sign, especially if it increases.num_err_log_entries: Controller error log entries. Some drives keep old entries forever, so I care more about changes than one old value.
percentage_used is probably the most misunderstood value. My SSD at 5% used is not "95% healthy" in a precise way. It only means the drive firmware estimates that around 5% of its specified write endurance was used. Still, a rapidly rising value can identify a workload problem.
For raw JSON output, which is easier to parse in scripts, I use:
$ sudo nvme smart-log /dev/nvme0 -o json | jq
Checking critical warnings and the error log
The critical warning field is a bit mask. 0 is fine. A value other than zero can indicate low spare capacity, temperature problems, reliability degradation, read-only mode or volatile memory backup failure.
You can inspect the error log separately:
$ sudo nvme error-log /dev/nvme0 -e 16
One old error entry does not always mean the drive is failing. I have seen entries caused by an unclean shutdown or a controller reset. New entries appearing regularly, combined with media errors or filesystem I/O errors in journalctl, are different.
$ sudo journalctl -k | grep -Ei 'nvme|I/O error|critical medium'
If the root filesystem is encrypted, I also make sure I have tested recovery access before doing maintenance. My setup uses TPM based unlocking on some systems, similar to my LUKS TPM2 Unlock with systemd-cryptenroll and Secure Boot setup.
Running an NVMe self-test
Most modern NVMe drives support device self-tests. A short test is usually safe to run while the system is online:
$ sudo nvme device-self-test /dev/nvme0 -s 1
For the extended test:
$ sudo nvme device-self-test /dev/nvme0 -s 2
Afterwards, read the result:
$ sudo nvme self-test-log /dev/nvme0
The extended test can take some time and may add noticeable load. I run it during a maintenance window on homelab systems, especially before I reuse a drive in a Proxmox host.
A self-test checks the drive, not your filesystem. If
btrfs, ZFS or ext4 already reports errors, check the filesystem and backups too.
A small systemd health report
I use a small script that writes reports to the journal and makes the service fail if it sees an obvious problem. Create /usr/local/sbin/nvme-health-report:
#!/bin/bash
set -eu
failed=0
for device in /dev/nvme[0-9]; do
[ -e "$device" ] || continue
smart=$(nvme smart-log "$device" -o json)
critical=$(jq -r '.critical_warning' <<< "$smart")
temp=$(jq -r '.temperature' <<< "$smart")
spare=$(jq -r '.available_spare' <<< "$smart")
threshold=$(jq -r '.available_spare_threshold' <<< "$smart")
used=$(jq -r '.percentage_used' <<< "$smart")
media=$(jq -r '.media_errors' <<< "$smart")
logger -t nvme-health "$device: critical=$critical temp=${temp}C spare=${spare}% used=${used}% media_errors=$media"
if [ "$critical" -ne 0 ] || [ "$spare" -lt "$threshold" ] || \
[ "$temp" -ge 70 ] || [ "$media" -gt 0 ]; then
logger -p user.alert -t nvme-health "Attention needed for $device"
failed=1
fi
done
exit "$failed"
Make it executable:
$ sudo chmod 0755 /usr/local/sbin/nvme-health-report
Then create /etc/systemd/system/nvme-health.service:
[Unit]
Description=NVMe SMART health report
OnFailure=nvme-health-alert@%n.service
[Service]
Type=oneshot
ExecStart=/usr/local/sbin/nvme-health-report
The alert unit sends a high priority message to the journal:
# /etc/systemd/system/nvme-health-alert@.service
[Service]
Type=oneshot
ExecStart=/usr/bin/logger -p user.alert -t nvme-health "NVMe health check failed: %i"
Finally add the timer:
# /etc/systemd/system/nvme-health.timer
[Unit]
Description=Daily NVMe health report
[Timer]
OnCalendar=daily
Persistent=true
RandomizedDelaySec=30m
[Install]
WantedBy=timers.target
Enable and test it:
$ sudo systemctl daemon-reload
$ sudo systemctl enable --now nvme-health.timer
$ sudo systemctl start nvme-health.service
$ journalctl -t nvme-health -n 20
For servers, I usually forward user.alert journal messages to my monitoring or mail setup. The unit failure itself is also visible in systemctl --failed.
If you want to understand timers, units and failure handlers in more detail, the German systemd training from cmt.de looks like a useful hands-on option.
The temperature limit in the script is intentionally conservative. Adjust it for your drive and cooling situation, but do not ignore a value that slowly gets worse. If you know a better way to handle NVMe alerts, let me know.