Surveiller l’état de santé d’un disque dur sous Linux avec les outils SMART
- Mise à jour le 19 juil. 2025
Introduction à la surveillance des disques avec SMART sous Linux
Selon Wikipedia, S.M.A.R.T. (Self-Monitoring, Analysis and Reporting Technology) est un système de surveillance intégré à la plupart des disques durs (HDD) et des disques SSD. Il permet de détecter et signaler divers indicateurs de fiabilité, afin d’anticiper les pannes matérielles potentielles.
Dans ce guide, nous verrons comment lire les attributs SMART à l’aide de l’outil smartctl
sur les systèmes GNU/Linux.
Configuration
- OS: Debian 13 trixie
- smartmontools: 7.4
Installation
Installez smartmontools depuis les dépôts officiels de Debian :
root@host:~# apt update && apt install smartmontools
Commandes
Commandes de base
- Vérifier si SMART est activé sur le disque :
root@host:~# smartctl -i /dev/<device>
- Activer la prise en charge de SMART :
root@host:~# smartctl -s on /dev/<device>
- Afficher tous les attributs SMART :
root@host:~# smartctl -a /dev/<device>
- Vérifier les attributs critiques. Dans l’exemple ci-dessous, une panne de disque est imminente :
root@host:~# smartctl -a /dev/<device> | grep -Ei "Reallocated|Spin.*Retry|SATA*Downshift|End-to-End|Reported.*Uncorrectable|Timeout|Reallocation|Current.*Pending|Uncorrect|TA.*Counter|Drive.*Life.*Protection"
5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - 408
10 Spin_Retry_Count 0x0013 100 100 097 Pre-fail Always - 0
187 Reported_Uncorrect 0x0032 075 075 000 Old_age Always - 25
188 Command_Timeout 0x0032 100 100 000 Old_age Always - 0
197 Current_Pending_Sector 0x0012 100 100 000 Old_age Always - 0
198 Offline_Uncorrectable 0x0010 100 100 000 Old_age Offline - 0
Contrôleurs RAID
Contrôleur Dell PERC
- Vérifier le disque numéro 8 derrière le contrôleur MegaRAID :
root@host:~# smartctl -a -d megaraid,8 /dev/sda
Contrôleur HP Smart Array
- Vérifier le disque numéro 1 derrière le contrôleur CCISS :
root@host:~# smartctl -a -d cciss,0 /dev/sda
Lancer des tests SMART
Cette section montre comment exécuter différents autotests SMART sur un disque.
Test court
- Test rapide avec une grande probabilité de détecter un problème matériel :
root@host:~# smartctl -t short /dev/<device>
Test long
- Effectue un balayage complet de la surface du disque :
root@host:~# smartctl -t long /dev/<device>
Test de transport
- Détecte d’éventuels dégâts survenus lors du transport du disque :
root@host:~# smartctl -t conveyance /dev/<device>
Vérifier l’état actuel des tests
- Voir l’avancement ou le résultat des autotests en cours ou terminés :
root@host:~# smartctl -l selftest /dev/<device>
Afficher un résumé de l’état de santé
- Afficher un état rapide de santé du disque :
root@host:~# smartctl -H /dev/<device>
Rechercher les erreurs
- Consulter les journaux des tests précédents et les erreurs enregistrées :
root@host:~# smartctl -l selftest /dev/<device>
root@host:~# smartctl -l error /dev/<device>
Configurer des alertes par email en cas de panne de disque SMART
Il est recommandé de configurer smartmontools pour envoyer des alertes par email lorsqu’un disque montre des signes avant-coureurs. Ci-dessous se trouve une configuration minimale utilisant le client léger msmtp
.
Installer msmtp
- Installer
msmtp
:
root@host:~# apt update && apt install msmtp
Configurer /etc/msmtprc
Éditez le fichier /etc/msmtprc
et adaptez-le à votre fournisseur SMTP. Ci-dessous, un exemple de configuration pour SMTP via TLS sur le port 465. Remplacez les valeurs par vos informations réelles :
- Serveur mail :
mail.example.com
- Protocole : SMTP via TLS (port 465)
- Identifiant :
smart@std.rocks
- Mot de passe : utilisez un mot de passe spécifique à l’application ou
passwordeval
(évitez le texte en clair)
account STD
#Mail Server :
host mail.std.rocks
port 465
from smart@std.rocks
#LOGIN / PASSWORD
user smart@std.rocks
password MyWeakPassword
auth on
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
tls_certcheck off
logfile /var/log/msmtp
account default : STD
Créer le script de notification
Créez le fichier /usr/local/sbin/smartdnotify.sh
. Ce script sera exécuté par smartd
à chaque avertissement ou erreur, et il enverra un email via msmtp
:
#!/bin/sh
# Send email
LANG=C
rm -f /tmp/mailsmart.header
echo "From: $SMARTD_ADDRESS" >> /tmp/mailsmart.header
echo "To: smart@std.rocks" >> /tmp/mailsmart.header
echo "Date: "`/bin/date -R` >> /tmp/mailsmart.header
echo "Subject: $SMARTD_FAILTYPE" >> /tmp/mailsmart.header
echo "Content-type: text/plain; charset=utf-8" >> /tmp/mailsmart.header
echo "Content-Disposition: inline" >> /tmp/mailsmart.header
echo "Content-Transfer-Encoding: 8bit" >> /tmp/mailsmart.header
echo "MIME-Version: 1.0" >> /tmp/mailsmart.header
echo "" >> /tmp/mailsmart.header
echo "$SMARTD_MESSAGE" >> /tmp/mailsmart.header
cat /tmp/mailsmart.header | /usr/bin/msmtp -f smart@std.rocks smart@std.rocks
rm -f /tmp/mailsmart.header
- Définissez les permissions appropriées afin que
smartd
puisse exécuter le script de notification :
root@host:~# chmod +x /usr/local/sbin/smartdnotify.sh
- Éditez le fichier
/etc/smartd.conf
et ajoutez une directiveDEVICESCAN
. Cela permettra d’analyser tous les disques disponibles et d’exécuter le script de notification en cas d’alerte :
# The word DEVICESCAN will cause any remaining lines in this
# configuration file to be ignored: it tells smartd to scan for all
# ATA and SCSI devices. DEVICESCAN may be followed by any of the
# Directives listed below, which will be applied to all devices that
# are found. Most users should comment out DEVICESCAN and explicitly
# list the devices that they wish to monitor.
DEVICESCAN -m smart@std.rocks -M exec /usr/local/sbin/smartdnotify.sh
- Redémarrez le service
smartd
root@host:~# systemctl restart smartd