Come controllare l'integrità di SSD/HDD in Linux
Su questa pagina
- Prerequisiti
- Installa Smartctl
- Testare l'integrità di SSD/HDD
- Conclusione
Se sei un amministratore di sistema e sei responsabile della gestione dei sistemi Linux in Datacenter. Quindi, si consiglia di controllare regolarmente lo stato delle unità SSD e HDD. Ti aiuterà a identificare le unità guaste e possono essere sostituite prima che si verifichi una perdita di dati. S.M.A.R.T è uno strumento utilizzato per monitorare lo stato di salute di SSD e HDD. Consente inoltre di eseguire test su richiesta sull'unità.
In questo post, ti mostreremo come controllare l'integrità di SSD e HDD su Linux.
Prerequisiti
- Un server o desktop con sistema operativo Linux.
- Sul server è configurata una password di root.
Installa Smartctl
Per impostazione predefinita, Smartctl è incluso nel repository predefinito di tutte le principali distribuzioni Linux.
Per la distribuzione Debian e Ubuntu, installa Smartctl usando il seguente comando:
apt-get install smartmontools -y
Per la distribuzione RHEL, CentOS e Fedora, installa Smartctl utilizzando il seguente comando:
dnf install smartmontools
Dopo aver installato Smartctl, avviare il servizio Smartctl utilizzando il seguente comando:
systemctl start smartd
Puoi controllare lo stato dello smartd con il seguente comando:
systemctl status smartd
Dovresti ottenere il seguente output:
? smartmontools.service - Self Monitoring and Reporting Technology (SMART) Daemon Loaded: loaded (/lib/systemd/system/smartmontools.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2021-07-02 08:58:33 UTC; 11s ago Docs: man:smartd(8) man:smartd.conf(5) Main PID: 1042 (smartd) Status: "Next check of 0 devices will start at 09:28:33" Tasks: 1 (limit: 2353) Memory: 1.2M CGroup: /system.slice/smartmontools.service ??1042 /usr/sbin/smartd -n Jul 02 08:58:33 ubunt4 smartd[1042]: Device: /dev/sda, opened Jul 02 08:58:33 ubunt4 smartd[1042]: Device: /dev/sda, [QEMU QEMU HARDDISK 2.5+], 53.6 GB Jul 02 08:58:33 ubunt4 smartd[1042]: Device: /dev/sda, IE (SMART) not enabled, skip device Jul 02 08:58:33 ubunt4 smartd[1042]: Try 'smartctl -s on /dev/sda' to turn on SMART features Jul 02 08:58:33 ubunt4 smartd[1042]: Device: /dev/sdb, opened Jul 02 08:58:33 ubunt4 smartd[1042]: Device: /dev/sdb, [AN Volume 2.5+], S/N: sdb, 53.6 GB Jul 02 08:58:33 ubunt4 smartd[1042]: Device: /dev/sdb, IE (SMART) not enabled, skip device Jul 02 08:58:33 ubunt4 smartd[1042]: Try 'smartctl -s on /dev/sdb' to turn on SMART features Jul 02 08:58:33 ubunt4 smartd[1042]: Monitoring 0 ATA/SATA, 0 SCSI/SAS and 0 NVMe devices Jul 02 08:58:33 ubunt4 systemd[1]: Started Self Monitoring and Reporting Technology (SMART) Daemon.
Testare l'integrità di SSD/HDD
Dopo aver installato Smartctl, dovrai attivare le funzionalità SMART sul tuo disco rigido.
Puoi farlo usando il seguente comando:
smartctl -s on /dev/sda
La prima cosa che devi fare è ottenere informazioni su SSD o HDD.
Puoi farlo usando il seguente comando:
smartctl -i /dev/sda
Questo ti darà le informazioni dettagliate del tuo disco rigido.
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-148-generic] (local build) Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org === START OF INFORMATION SECTION === Device Model: WDC WD5000LPVX-75V0TT0 Serial Number: WXV1EC4KN2N7 LU WWN Device Id: 5 0014ee 65af65611 Firmware Version: 01.01A01 User Capacity: 500,107,862,016 bytes [500 GB] Sector Sizes: 512 bytes logical, 4096 bytes physical Rotation Rate: 5400 rpm Device is: Not in smartctl database [for details use: -P showall] ATA Version is: ACS-2 (minor revision not indicated) SATA Version is: SATA 3.0, 6.0 Gb/s (current: 3.0 Gb/s) Local Time is: Fri Jul 2 14:39:33 2021 IST SMART support is: Available - device has SMART capability. SMART support is: Enabled
Se desideri eseguire un breve test sull'unità, esegui il seguente comando:
smartctl -t short -a /dev/sda
Dovresti ottenere il seguente output:
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-148-generic] (local build) Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org === START OF INFORMATION SECTION === Device Model: WDC WD5000LPVX-75V0TT0 Serial Number: WXV1EC4KN2N7 LU WWN Device Id: 5 0014ee 65af65611 Firmware Version: 01.01A01 User Capacity: 500,107,862,016 bytes [500 GB] Sector Sizes: 512 bytes logical, 4096 bytes physical Rotation Rate: 5400 rpm Device is: Not in smartctl database [for details use: -P showall] ATA Version is: ACS-2 (minor revision not indicated) SATA Version is: SATA 3.0, 6.0 Gb/s (current: 3.0 Gb/s) Local Time is: Fri Jul 2 14:40:23 2021 IST SMART support is: Available - device has SMART capability. SMART support is: Enabled === START OF READ SMART DATA SECTION === SMART overall-health self-assessment test result: PASSED General SMART Values: Offline data collection status: (0x00) Offline data collection activity was never started. Auto Offline Data Collection: Disabled. Self-test execution status: ( 0) The previous self-test routine completed without error or no self-test has ever been run. Total time to complete Offline data collection: ( 9360) seconds. Offline data collection capabilities: (0x7b) SMART execute Offline immediate. Auto Offline data collection on/off support.
Il breve test metterà alla prova le proprietà elettriche, le proprietà meccaniche e la lettura/verifica.
Per trovare e stampare il risultato dell'autotest, eseguire il seguente comando:
smartctl -l selftest /dev/sda
Dovresti ottenere il seguente output:
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-148-generic] (local build) Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org === START OF READ SMART DATA SECTION === SMART Self-test log structure revision number 1 Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error # 1 Short offline Completed without error 00% 7609 - # 2 Short offline Interrupted (host reset) 90% 6972 - # 3 Short offline Aborted by host 70% 6972 - # 4 Short offline Interrupted (host reset) 70% 2 -
Per eseguire un lungo test, utilizzare il seguente comando:
smartctl -t long -a /dev/sda
Dovresti ottenere il seguente output:
SMART Selective self-test log data structure revision number 1 SPAN MIN_LBA MAX_LBA CURRENT_TEST_STATUS 1 0 0 Not_testing 2 0 0 Not_testing 3 0 0 Not_testing 4 0 0 Not_testing 5 0 0 Not_testing Selective self-test flags (0x0): After scanning selected spans, do NOT read-scan remainder of disk. If Selective self-test is pending on power-up, resume after 0 minute delay. === START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION === Sending command: "Execute SMART Extended self-test routine immediately in off-line mode". Drive command "Execute SMART Extended self-test routine immediately in off-line mode" successful. Testing has begun. Please wait 107 minutes for test to complete. Test will complete after Fri Jul 2 16:30:41 2021 Use smartctl -X to abort test.
Il test lungo testerà tutto ciò che è incluso nel test breve.
Puoi interrompere il test, eseguire il seguente comando:
smartctl -X /dev/sda
Dovresti vedere il seguente output:
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-148-generic] (local build) Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org === START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION === Sending command: "Abort SMART off-line mode self-test routine". Self-testing aborted!
Per testare l'integrità generale dell'unità, eseguire il seguente comando:
smartctl -d ata -H /dev/sda
Dovresti ottenere il seguente output:
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-148-generic] (local build) Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org === START OF READ SMART DATA SECTION === SMART overall-health self-assessment test result: PASSED
Per controllare il tempo stimato per eseguire il test, eseguire il seguente comando:
smartctl -c /dev/sda
Dovresti ottenere il seguente output:
smartctl 6.2 2013-07-26 r3841 [x86_64-linux-4.4.0-148-generic] (local build) Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org === START OF READ SMART DATA SECTION === General SMART Values: Offline data collection status: (0x00) Offline data collection activity was never started. Auto Offline Data Collection: Disabled. Self-test execution status: ( 25) The self-test routine was aborted by the host. Total time to complete Offline data collection: ( 9360) seconds. Offline data collection capabilities: (0x7b) SMART execute Offline immediate. Auto Offline data collection on/off support. Suspend Offline collection upon new command. Offline surface scan supported. Self-test supported. Conveyance Self-test supported. Selective Self-test supported. SMART capabilities: (0x0003) Saves SMART data before entering power-saving mode. Supports SMART auto save timer. Error logging capability: (0x01) Error logging supported. General Purpose Logging supported. Short self-test routine recommended polling time: ( 2) minutes. Extended self-test routine recommended polling time: ( 107) minutes. Conveyance self-test routine recommended polling time: ( 5) minutes. SCT capabilities: (0x7035) SCT Status supported. SCT Feature Control supported. SCT Data Table supported.
Per stampare solo il registro degli errori, eseguire il seguente comando:
smartctl -l error /dev/sda
Per ottenere informazioni sulla guida, eseguire il seguente comando:
smartctl --help
Conclusione
Nella guida sopra, hai imparato come installare e utilizzare lo strumento S.M.A.R.T per controllare lo stato delle tue unità SSH e HDD. Spero che questo ti aiuti molto. Per ulteriori informazioni, leggi la pagina man di smartctl.