一、命令简介
smartctl 命令用于获取硬盘的 SMART 信息。
介绍硬盘SMART
硬盘的 SMART (Self-Monitoring, Analysis, and Reporting Technology) 技术用于监控硬盘的健康状态,并能提供一些潜在故障的预警信息。通过查看 SMART 数据,用户可以了解硬盘的各种属性和状态,如错误率、温度、使用寿命等。
安装smartctl
sudo install smartmontools
检查硬盘的 SMART 状态
sudo smartctl -a /dev/sda
更详细的用例请参考后继章节
与硬盘相关命令
- gdisk、fdisk 命令,磁盘分区管理。
- mkfs 命令,格式化。
- mdadm 命令,管理软 RAID。
- lsblk 命令,列出块设备(包含磁盘)信息。
- df 命令,磁盘余量
- smartctl 命令,读取磁盘 SMART 信息
二、命令参数
格式
smartctl 选项 硬盘
需要sudo权限运行。
选项:
- -a, --all:显示所有 SMART 信息。
- -H, --health:显示硬盘的健康状态。
- -i, --info:显示硬盘的基本信息。
- -l selftest:显示自检结果。
- -t <test>:启动自检,如short(短自检)或long(长自检)。
- -c, --capabilities:显示硬盘的 SMART 能力。
- -x, --xall:显示扩展 SMART 信息。
- -l error:显示错误日志。
- -A, --attributes:显示 SMART 属性。
- -s, --smart=on|off:启用或禁用 SMART 功能。
- -d, --device=TYPE:指定硬盘的接口类型,如ata,scsi,sat,nvme 等。
参数:
- /dev/sdX:指定要检查的硬盘设备路径,如/dev/sda。
- test:自检类型,如short,long。
- TYPE:硬盘接口类型,如ata,scsi,sat,nvme。
三、命令示例
显示硬盘的基本信息
sudo smartctl -i /dev/sdX
输出
  
显示硬盘的 SMART 属性
sudo smartctl -A /dev/sdX
输出
soulio@k455l:~$ sudo smartctl -A /dev/sdb
smartctl 7.2 2020-12-30 r5155 [x86_64-linux-6.5.0-35-generic] (local build)
Copyright (C) 2002-20, 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     0x002f   100   100   051    Pre-fail  Always       -       6
  2 Throughput_Performance  0x0027   252   252   000    Pre-fail  Always       -       0
  3 Spin_Up_Time            0x0023   095   091   025    Pre-fail  Always       -       1651
  4 Start_Stop_Count        0x0032   096   096   000    Old_age   Always       -       4478
  5 Reallocated_Sector_Ct   0x0033   252   252   010    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x002f   252   252   051    Pre-fail  Always       -       0
  8 Seek_Time_Performance   0x0025   252   252   015    Pre-fail  Offline      -       0
  9 Power_On_Hours          0x0032   100   100   000    Old_age   Always       -       12284
 10 Spin_Retry_Count        0x0033   252   252   051    Pre-fail  Always       -       0
 11 Calibration_Retry_Count 0x0032   100   100   000    Old_age   Always       -       175
 12 Power_Cycle_Count       0x0032   097   097   000    Old_age   Always       -       3057
181 Program_Fail_Cnt_Total  0x0022   100   100   000    Old_age   Always       -       9022488
183 Runtime_Bad_Block       0x0032   252   252   010    Old_age   Always       -       0
184 End-to-End_Error        0x0033   252   252   048    Pre-fail  Always       -       0
186 Unknown_Attribute       0x0032   252   252   000    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   252   252   000    Old_age   Always       -       0
188 Command_Timeout         0x0032   252   252   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0002   066   050   040    Old_age   Always       -       34 (Min/Max 8/50)
191 G-Sense_Error_Rate      0x0022   100   100   000    Old_age   Always       -       77
192 Power-Off_Retract_Count 0x0022   100   100   000    Old_age   Always       -       79
193 Load_Cycle_Count        0x0032   001   001   000    Old_age   Always       -       1103480
194 Temperature_Celsius     0x0002   064   050   000    Old_age   Always       -       34 (Min/Max 8/50)
195 Hardware_ECC_Recovered  0x003a   100   100   000    Old_age   Always       -       0
196 Reallocated_Event_Count 0x0032   252   252   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0032   252   252   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0030   252   252   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x0036   200   200   000    Old_age   Always       -       0
200 Multi_Zone_Error_Rate   0x002a   100   100   000    Old_age   Always       -       1663
启动短自检
sudo smartctl -t short /dev/sdX
输出
soulio@k455l:~$ sudo smartctl -t /dev/sdb
smartctl 7.2 2020-12-30 r5155 [x86_64-linux-6.5.0-35-generic] (local build)
Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org
=======> INVALID ARGUMENT TO -t: /dev/sdb
=======> VALID ARGUMENTS ARE: offline, short, long, conveyance, force, vendor,N, select,M-N, pending,N, afterselect,[on|off] <=======
Use smartctl -h to get a usage summary
获取硬盘温度
sudo smartctl -a /dev/sdX | grep Temperature
输出
  
启用 SMART 功能
sudo smartctl -s on /dev/sdX
默认就是打开的。
指明硬盘类型
有时我们使用 USB 外挂的硬盘,使用 smartctl 命令可能会提示“无法识别磁盘类型”。需要使用 -d 参数手动指明硬盘类型,比如 sat 类型。
$ sudo smartctl -d sat -a /dev/sdc | grep Temperature
190 Airflow_Temperature_Cel 0x0022   058   047   045    Old_age   Always       -       42 (Min/Max 18/42)
194 Temperature_Celsius     0x0022   042   053   000    Old_age   Always       -       42 (0 4 0 0 0)

![[极客大挑战 2019]EasySQL1](https://i-blog.csdnimg.cn/direct/64f88195d9684691a74bb98b6368f723.jpeg)

















