阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

硬盘监控和分析工具:Smartctl

178次阅读
没有评论

共计 6346 个字符,预计需要花费 16 分钟才能阅读完成。

Smartctl(S.M.A.R.T 自监控,分析和报告技术)是类 Unix 系统下实施 SMART 任务命令行套件或工具,它用于打印 SMART自检 错误日志 ,启用并禁用 SMRAT 自动检测,以及初始化设备自检。

Smartctl 对于 Linux 物理服务器十分有用,在这些服务器上,可以对智能磁盘进行错误检查,并将与 硬件 RAID相关的磁盘信息摘录下来。

在本帖中,我们将讨论 smartctl 命令的一些实用样例。如果你的 Linux 上海没有安装 smartctl,请按以下步骤来安装。

硬盘监控和分析工具:Smartctl

使用 Smartctl 查 Dell 服务器坏道实录  http://www.linuxidc.com/Linux/2012-07/65723.htm

安装 Smartctl

对于 Ubuntu

  1. $ sudo aptget install smartmontools

对于 CentOS & RHEL

  1. # yum install smartmontools

启动 Smartctl 服务

对于 Ubuntu

  1. $ sudo /etc/init.d/smartmontools start

对于 CentOS & RHEL

  1. # service smartd start ; chkconfig smartd on

样例

样例:1 检查磁盘的 Smart 功能是否启用

  1. root@linuxtechi:~# smartctl i /dev/sdb
  2. smartctl 6.220130726 r3841 [x86_64linux3.13.032generic](local build)
  3. Copyright(C)200213,BruceAllen,ChristianFranke, www.smartmontools.org
  4.  
  5. === START OF INFORMATION SECTION ===
  6. ModelFamily:SeagateMomentus5400.6
  7. DeviceModel: ST9320325AS
  8. SerialNumber:5VD2V59T
  9. LU WWN DeviceId:5000c50020a37ec4
  10. FirmwareVersion:0002BSM1
  11. UserCapacity:320,072,933,376 bytes [320 GB]
  12. SectorSize:512 bytes logical/physical
  13. RotationRate:5400 rpm
  14. Deviceis:In smartctl database [for details use:P show]
  15. ATA Versionis: ATA8ACS T13/1699D revision 4
  16. SATA Versionis: SATA 2.6,1.5Gb/s
  17. LocalTimeis:SunNov1612:32:092014 IST
  18. SMART support is:Available device has SMART capability.
  19. SMART support is:Enabled

这里‘/dev/sdb’是你的硬盘。上面输出中的最后两行显示了 SMART 功能已启用。

样例:2 启用磁盘的 Smart 功能

  1. root@linuxtechi:~# smartctl s on /dev/sdb
  2. smartctl 6.220130726 r3841 [x86_64linux3.13.032generic](local build)
  3. Copyright(C)200213,BruceAllen,ChristianFranke, www.smartmontools.org
  4.  
  5. === START OF ENABLE/DISABLE COMMANDS SECTION ===
  6. SMART Enabled.

样例:3 禁用磁盘的 Smart 功能

  1. root@linuxtechi:~# smartctl s off /dev/sdb
  2. smartctl 6.220130726 r3841 [x86_64linux3.13.032generic](local build)
  3. Copyright(C)200213,BruceAllen,ChristianFranke, www.smartmontools.org
  4.  
  5. === START OF ENABLE/DISABLE COMMANDS SECTION ===
  6. SMART Disabled.Use option s with argument ‘on’ to enable it.

样例:4 显示磁盘的详细 Smart 信息

  1. root@linuxtechi:~# smartctl a /dev/sdb // For IDE drive
  2. root@linuxtechi:~# smartctl a d ata /dev/sdb // For SATA drive

样例:5 显示磁盘总体健康状况

  1. root@linuxtechi:~# smartctl H /dev/sdb
  2. smartctl 6.220130726 r3841 [x86_64linux3.13.032generic](local build)
  3. Copyright(C)200213,BruceAllen,ChristianFranke, www.smartmontools.org
  4.  
  5. === START OF READ SMART DATA SECTION ===
  6. SMART overallhealth selfassessment test result: PASSED
  7. Warning:This result is based on an Attribute check.
  8. Please note the following marginal Attributes:
  9. ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
  10. 190Airflow_Temperature_Cel0x0022067045045Old_ageAlwaysIn_the_past33(Min/Max25/33)

样例:6 使用 long 和 short 选项测试硬盘

Long 测试

  1. root@linuxtechi:~# smartctl test=long/dev/sdb
  2. smartctl 6.220130726 r3841 [x86_64linux3.13.032generic](local build)
  3. Copyright(C)200213,BruceAllen,ChristianFranke, www.smartmontools.org
  4.  
  5. === START OF OFFLINE IMMEDIATE AND SELFTEST SECTION ===
  6. Sending command:“Execute SMART Extended self-test routine immediately in off-line mode”.
  7. Drive command “Execute SMART Extended self-test routine immediately in off-line mode” successful.
  8. Testing has begun.
  9. Please wait 102 minutes for test to complete.
  10. Test will complete after SunNov1614:29:432014
  11.  
  12. Use smartctl X to abort test.

或者,我们可以重定向测试输出到日志文件,就像下面这样

  1. root@linuxtechi:~# smartctl test=long/dev/sdb >/var/log/long.text

Short 测试

  1. root@linuxtechi:~# smartctl test=short/dev/sdb
  2. smartctl 6.220130726 r3841 [x86_64linux3.13.032generic](local build)
  3. Copyright(C)200213,BruceAllen,ChristianFranke, www.smartmontools.org
  4.  
  5. === START OF OFFLINE IMMEDIATE AND SELFTEST SECTION ===
  6. Sending command:“Execute SMART Short self-test routine immediately in off-line mode”.
  7. Drive command “Execute SMART Short self-test routine immediately in off-line mode” successful.
  8. Testing has begun.
  9. Please wait 1 minutes for test to complete.
  10. Test will complete after SunNov1612:51:452014
  11.  
  12. Use smartctl X to abort test.

  1. root@linuxtechi:~# smartctl test=short/dev/sdb >/var/log/short.text

注意:short 测试将花费最多 2 分钟,而在 long 测试中没有时间限制,因为它会读取并验证磁盘的每个段。

样例:7 查看驱动器的自检结果

  1. root@linuxtechi:~# smartctl l selftest /dev/sdb
  2. smartctl 6.220130726 r3841 [x86_64linux3.13.032generic](local build)
  3. Copyright(C)200213,BruceAllen,ChristianFranke, www.smartmontools.org
  4.  
  5. === START OF READ SMART DATA SECTION ===
  6. SMART Selftest log structure revision number 1
  7. NumTest_DescriptionStatusRemainingLifeTime(hours) LBA_of_first_error
  8. # 1 Short offline Completed: read failure 90% 492 210841222
  9. # 2 Extended offline Completed: read failure 90% 492 210841222

样例:8 计算测试时间估值

  1. root@linuxtechi:~# smartctl c /dev/sdb
  2. smartctl 6.220130726 r3841 [x86_64linux3.13.032generic](local build)
  3. Copyright(C)200213,BruceAllen,ChristianFranke, www.smartmontools.org
  4.  
  5. === START OF READ SMART DATA SECTION ===
  6. General SMART Values:
  7. Offline data collection status:(0x00)Offline data collection activity
  8. was never started.
  9. AutoOfflineDataCollection:Disabled.
  10. Selftest execution status:(121)The previous selftest completed having
  11. the read element of the test failed.
  12. Total time to complete Offline
  13. data collection:(0) seconds.
  14. Offline data collection
  15. capabilities:(0x73) SMART execute Offline immediate.
  16. AutoOffline data collection on/off support.
  17. SuspendOffline collection upon new
  18. command.
  19. NoOffline surface scan supported.
  20. Selftest supported.
  21. ConveyanceSelftest supported.
  22. SelectiveSelftest supported.
  23. SMART capabilities:(0x0003)Saves SMART data before entering
  24. powersaving mode.
  25. Supports SMART auto save timer.
  26. Error logging capability:(0x01)Error logging supported.
  27. GeneralPurposeLogging supported.
  28. Shortselftest routine
  29. recommended polling time:(1) minutes.
  30. Extendedselftest routine
  31. recommended polling time:(102) minutes.
  32. Conveyanceselftest routine
  33. recommended polling time:(2) minutes.
  34. SCT capabilities:(0x103b) SCT Status supported.
  35. SCT ErrorRecoveryControl supported.
  36. SCT FeatureControl supported.
  37. SCT DataTable supported.

样例:9 显示磁盘错误日志

  1. root@linuxtechi:~# smartctl l error /dev/sdb
  2.  
  3. SampleOutput
  4.  
  5. smartctl 6.220130726 r3841 [x86_64linux3.13.032generic](local build)
  6. Copyright(C)200213,BruceAllen,ChristianFranke, www.smartmontools.org
  7.  
  8. === START OF READ SMART DATA SECTION ===
  9. SMART ErrorLogVersion:1
  10. ATA ErrorCount:5
  11. CR =CommandRegister[HEX]
  12. FR =FeaturesRegister[HEX]
  13. SC =SectorCountRegister[HEX]
  14. SN =SectorNumberRegister[HEX]
  15. CL =CylinderLowRegister[HEX]
  16. CH =CylinderHighRegister[HEX]
  17. DH =Device/HeadRegister[HEX]
  18. DC =DeviceCommandRegister[HEX]
  19. ER =Errorregister[HEX]
  20. ST =Statusregister[HEX]
  21. Powered_Up_Timeis measured from power on,and printed as
  22. DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,
  23. SS=sec,and sss=millisec.It“wraps” after 49.710 days.
  24.  
  25. Commands leading to the command that caused the error were:
  26. CR FR SC SN CL CH DH DC Powered_Up_TimeCommand/Feature_Name
  27. —————-——————–
  28. 25 da 08 e7 e5 a5 4c0000:30:44.515 READ DMA EXT
  29. 25 da 08 df e5 a5 4c0000:30:44.514 READ DMA EXT
  30. 25 da 805f e5 a5 4c0000:30:44.502 READ DMA EXT
  31. 25 da f0 5f e6 a5 4c0000:30:44.496 READ DMA EXT
  32. 25 da 104f e6 a5 4c0000:30:44.383 READ DMA EXT
正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计6346字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中