smartctl 硬盘健康检查

什么是 Smartctl

Smartctl 是一个命令行工具,用于监测和分析硬盘的状态。它可以读取硬盘的 S.M.A.R.T(Self-Monitoring, Analysis, and Reporting Technology 其中包括健康状态、‌温度、‌错误率)信息,并且可以通过这些信息来预测硬盘故障的可能性。

Smartctl 的作用

Smartctl 可以帮助我们检测出可能出现故障的硬盘,并在故障前采取相应的措施,以减少数据丢失和系统停机的风险。

如何安装 Smartctl

本机已安装smartctl,通过如下命令可确认smartctl所属的软件包:smartmontools

[root@localhost ~]# which smartctl | xargs rpm -qf
smartmontools-7.1-1.ky10.x86_64

#可使用apt-get或者yum安装:
sudo apt-get install smartmontools
sudo yum install smartmontools

基本使用方式:

环境介绍:/dev/sda为 raid 5 磁盘组(含4块磁盘),/dev/sdc为 jbod 直通硬盘。
扫描现有磁盘:

[root@localhost ~]# smartctl --scan    #可以查看所有硬盘的设备路径,‌如/dev/sda。‌
/dev/sda -d scsi # /dev/sda, SCSI device
/dev/sdc -d scsi # /dev/sdc, SCSI device
/dev/bus/0 -d megaraid,0 # /dev/bus/0 [megaraid_disk_00], SCSI device
/dev/bus/0 -d megaraid,1 # /dev/bus/0 [megaraid_disk_01], SCSI device
/dev/bus/0 -d megaraid,2 # /dev/bus/0 [megaraid_disk_02], SCSI device
/dev/bus/0 -d megaraid,3 # /dev/bus/0 [megaraid_disk_03], SCSI device
/dev/bus/0 -d megaraid,4 # /dev/bus/0 [megaraid_disk_04], SCSI device

查看常规磁盘(非raid组内磁盘)健康状态:

sudo smartctl -a /dev/sda    #可以查看特定硬盘的详细SMART信息,‌包括健康状态、‌温度、‌错误率等。‌
sudo smartctl -H /dev/sda    #可以仅查看硬盘的健康状态,‌如果显示“PASSED”或者“OK”则表示硬盘运行正常,‌如果显示“FAILED”或“WARNING”则可能存在问题。‌

如果直接查看 raid 组的smart信息,会提示不支持:

[root@localhost ~]# smartctl -a /dev/sda
smartctl 7.1 2019-12-30 r5022 [x86_64-linux-4.19.90-24.4.v2101.ky10.x86_64] (local build)
Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Vendor:               AVAGO
……omit
=== START OF READ SMART DATA SECTION ===
Current Drive Temperature:     0 C
Drive Trip Temperature:        0 C

Error Counter logging not supported

Device does not support Self Test logging

查看raid组内磁盘的信息

需要使用scan输出信息中megaraid行的“#”之前的信息,来作为检查命令的参数:

[root@localhost ~]# smartctl -H /dev/bus/0 -d megaraid,3
smartctl 7.1 2019-12-30 r5022 [x86_64-linux-4.19.90-24.4.v2101.ky10.x86_64] (local build)
Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART Health Status: OK

或详细信息:

[root@localhost ~]# smartctl -a /dev/bus/0 -d megaraid,0
smartctl 7.1 2019-12-30 r5022 [x86_64-linux-4.19.90-24.4.v2101.ky10.x86_64] (local build)
Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
……omit

SMART Attributes Data Structure revision number: 16
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000b   100   100   016    Pre-fail  Always       -       0
  2 Throughput_Performance  0x0005   129   100   054    Pre-fail  Offline      -       104
  3 Spin_Up_Time            0x0007   137   100   024    Pre-fail  Always       -       309 (Average 310)
  4 Start_Stop_Count        0x0012   100   100   000    Old_age   Always       -       40
  5 Reallocated_Sector_Ct   0x0033   100   100   005    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000b   100   100   067    Pre-fail  Always       -       0
  8 Seek_Time_Performance   0x0005   128   100   020    Pre-fail  Offline      -       18
  9 Power_On_Hours          0x0012   096   096   000    Old_age   Always       -       30060
 10 Spin_Retry_Count        0x0013   100   100   060    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       40
192 Power-Off_Retract_Count 0x0032   099   099   000    Old_age   Always       -       1287
193 Load_Cycle_Count        0x0012   099   099   000    Old_age   Always       -       1287
194 Temperature_Celsius     0x0002   193   166   000    Old_age   Always       -       31 (Min/Max 20/36)
196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0022   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0008   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x000a   200   200   000    Old_age   Always       -       0

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Extended offline    Completed without error       00%        36         -
# 2  Short offline       Completed without error       00%        29         -
# 3  Extended offline    Completed without error       00%        17         -
# 4  Short offline       Completed without error       00%         9         -

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.

SAS磁盘的输出

smartctl 7.1 2019-12-30 r5022 [x86_64-linux-4.19.90-24.4.v2101.ky10.x86_64] (local build)
Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Vendor:               HGST
……omit

=== START OF READ SMART DATA SECTION ===
SMART Health Status: OK

Current Drive Temperature:     32 C
Drive Trip Temperature:        85 C

Manufactured in week 30 of year 2018
Specified cycle count over device lifetime:  50000
Accumulated start-stop cycles:  125
Specified load-unload count over device lifetime:  600000
Accumulated load-unload cycles:  156
Elements in grown defect list: 0

Vendor (Seagate Cache) information
  Blocks sent to initiator = 61858937569280

Error counter log:
           Errors Corrected by           Total   Correction     Gigabytes    Total
               ECC          rereads/    errors   algorithm      processed    uncorrected
           fast | delayed   rewrites  corrected  invocations   [10^9 bytes]  errors
read:          0       16         0        16       4343       1498.502           0
write:         0       43         0        43      25269        968.836           0
verify:        0        0         0         0      22004          0.685           0

Non-medium error count:        0

SMART Self-test log
Num  Test              Status                 segment  LifeTime  LBA_first_err [SK ASC ASQ]
     Description                              number   (hours)
# 1  Background long   Completed                   -      52                 - [-   -    -]
# 2  Background long   Completed                   -      24                 - [-   -    -]

Long (extended) Self-test duration: 34237 seconds [570.6 minutes]

一些输出信息的解释

TYPE

SMART Attributes Data中,每一项属性都有一个TYPE列,其中:

  • Pre-fail指该属性是指磁盘制造商认为可能会在磁盘出现故障之前发生变化的属性,这些属性的改变可能是磁盘健康状况恶化的早期迹象。
  • Old_age指该属性反映了硬盘随着时间的推移而自然老化的指标。这些属性的变化通常与磁盘的工作小时数、读写操作次数等因素有关,而非直接关联到可能引发故障的具体事件。

UPDATED

Offline的信息,这是某些属性只在磁盘离线时才被更新。
Always就是总是更新。

一些建议的关注指标【来自AI】

读错误率 (Read Error Rate):

  • 意义: 表示读取数据时发生的错误次数。
  • 重要性: 高读错误率可能表明磁盘即将出现故障。

重映射扇区计数 (Reallocated Sector Count):

  • 意义: 表示磁盘上已经被重映射到备用区域的坏扇区数量。
  • 重要性: 高重映射扇区计数可能意味着磁盘上有较多的坏扇区。

当前待映射扇区 (Current Pending Sector Count):

  • 意义: 表示尚未被重映射的潜在坏扇区数量。
  • 重要性: 高当前待映射扇区计数可能预示着磁盘即将出现故障。

离线未映射扇区 (Offline Uncorrectable Sector Count):

  • 意义: 表示在离线自检期间检测到的不可纠正的扇区数量。
  • 重要性: 高离线未映射扇区计数可能表明磁盘存在严重问题。

校验和错误 (Checksum Errors):

  • 意义: 表示在磁盘缓存中检测到的校验和错误数量。
  • 重要性: 高校验和错误可能表明磁盘缓存存在问题。

启动/停止周期计数 (Start/Stop Cycle Count):

  • 意义: 表示磁盘启动和停止的总次数。
  • 重要性: 高启动/停止周期计数可能表明磁盘经常断电,这可能会影响磁盘寿命。

寻道错误率 (Seek Error Rate):

  • 意义: 表示磁头定位时发生的错误次数。
  • 重要性: 高寻道错误率可能表明磁头定位有问题。

气流温度 (Airflow Temperature Celsius):

  • 意义: 表示磁盘内部的温度。
  • 重要性: 高温可能导致磁盘过热,影响磁盘性能和寿命。

电源接通时间 (Power-On Hours):

  • 意义: 表示磁盘自生产以来的累计运行时间。
  • 重要性: 长期运行时间可能表明磁盘接近其预期寿命。

SMART状态 (SMART Status):

  • 意义: 总体上表示磁盘的SMART状态,通常会报告为“PASSED”、“FAILED”或“UNKNOWN”。
  • 重要性: “FAILED”状态表明磁盘可能存在问题。
posted @ 2024-08-14 17:31  飞飞6779  阅读(196)  评论(0编辑  收藏  举报