![]()
测试环境:Debian 9 X64

硬盘的安全对于我们来说是至关重要的,特别是服务器,下面就介绍一些Linux下常用的硬盘检测命令。

1、硬盘SMART状态

SMART是一种磁盘自我分析检测技术,早在90年代末就基本得到了普及每一块硬盘(包括IDE、SCSI)在运行的时候,都会将自身的若干参数记录下来这些参数包括型号、容量、温度、密度、扇区、寻道时间、传输、误码率等硬盘运行了几千小时后,很多内在的物理参数都会发生变化某一参数超过报警阈值,则说明硬盘接近损坏此时硬盘依然在工作,如果用户不理睬这个报警继续使用那么硬盘将变得非常不可靠,随时可能故障。

安装
apt-get install smartmontools -y

命令:
smartctl -i /dev/sda
正常情况下应该会得到下面这样的信息

smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.9.0-9-amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Device Model:     HGST HUS726020ALA610
Serial Number:    K5J1HM3G
LU WWN Device Id: 5 000cca 25edcde00
Firmware Version: A5GNTD05
User Capacity:    2,000,398,934,016 bytes [2.00 TB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    7200 rpm
Form Factor:      3.5 inches
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   ACS-2, ATA8-ACS T13/1699-D revision 4
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 3.0 Gb/s)
Local Time is:    Mon May 13 21:25:36 2019 CST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

SMART support is: Enabled说明硬盘已经开启SMART,若未启动,可使用smartctl –smart=on –offlineauto=on –saveauto=on /dev/sda开启。

2、查看硬盘当前的健康状态

使用smartctl -H /dev/sda,若出现

smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.9.0-9-amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

请注意result后边的结果:PASSED,这表示硬盘健康状态良好
如果这里显示Failure,那么最好立刻给服务器更换硬盘。
不过,显示PASSED不一定完全没有问题,可使用smartctl -t short /dev/sda进行快速测试,显示:

smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.9.0-9-amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===
Sending command: "Execute SMART Short self-test routine immediately in off-line mode".
Drive command "Execute SMART Short self-test routine immediately in off-line mode" successful.
Testing has begun.
Please wait 2 minutes for test to complete.
Test will complete after Mon May 13 21:44:03 2019

Use smartctl -X to abort test.

执行完毕后请等待2分钟左右(视硬盘大小),然后执行smartctl -l selftest /dev/sda显示测试报告:

smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.9.0-9-amd64] (local build)
Copyright (C) 2002-16, 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%      2584         -

可发现Completed without error后面的百分数是0,说明硬盘状态良好,无坏道。

3、查看硬盘详细信息

执行如下命令可以看到硬盘详细的参数:
smartctl -A /dev/sda

smartctl 6.6 2016-05-31 r4324 [x86_64-linux-4.9.0-9-amd64] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
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   134   134   054    Pre-fail  Offline      -       119
  3 Spin_Up_Time            0x0007   144   144   024    Pre-fail  Always       -       216 (Average 200)
  4 Start_Stop_Count        0x0012   100   100   000    Old_age   Always       -       49
  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   140   140   020    Pre-fail  Offline      -       15
  9 Power_On_Hours          0x0012   100   100   000    Old_age   Always       -       2584
 10 Spin_Retry_Count        0x0013   100   100   060    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       47
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       115
193 Load_Cycle_Count        0x0012   100   100   000    Old_age   Always       -       115
194 Temperature_Celsius     0x0002   166   166   000    Old_age   Always       -       36 (Min/Max 16/49)
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

Power_On_Hours显示的是硬盘通电时间

最后修改:2021 年 07 月 04 日
如果觉得我的文章对你有用,请随意赞赏