加载中...

检测硬盘 SMART 健康状态


完全用 GNU/Linux 工作

29. 检测硬盘 S.M.A.R.T. 健康状态

S.M.A.R.T. 是个用来检测硬盘健康状况的指标,虽然前文 26. 使用 Clonezilla 打造不死的作业系统 提供了软件层面的备份方式,但硬件总有老旧、损坏的一天。而一台电脑中又以硬盘里的资料最为重要,这里冻仁将介绍 GNU/Linux 下检测、监控的方法。

2013-10-16-palimpsest-smart.png

▲ 在 GNOME 上我们可使用 磁盘公用程式 (GNOME Disks)1 来检测 SMART。

安装 smartmontools

套件 smartmontools 包含了 smartctl, smartd,是个可以监控 ATA, SCSI 硬盘 (storage) SMART (Self-Monitoring, Analysis and Reporting Technology System) 状态的工具。我们可以透过它来进阶设定各种硬盘退化、错误警告的回报机制。

安装文字接口的检测工具 smartmontools。

  1. # Debian, Ubuntu
  2. $ sudo aptitude install smartmontools
  3. # CentOS, RHEL, Fedora
  4. $ sudo yum install smartmontools

smartctl

smartctl 主要是用来进行一次性、暂时性的硬盘扫描,以下为常见的使用方法。

  1. 查看该媒体是否支援 SMART 检测。

  1. # - 啟用 (Enabled)。
  2. $ sudo smartctl -i /dev/sda
  3. smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.8.0-31-generic] (local build)
  4. Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net
  5. === START OF INFORMATION SECTION ===
  6. Device Model: ST3500413AS
  7. Serial Number: Z2AAMWCL
  8. LU WWN Device Id: 5 000c50 035f695b1
  9. Firmware Version: JC45
  10. User Capacity: 500,107,862,016 bytes [500 GB]
  11. Sector Size: 512 bytes logical/physical
  12. Device is: Not in smartctl database [for details use: -P showall]
  13. ATA Version is: 8
  14. ATA Standard is: ATA-8-ACS revision 4
  15. Local Time is: Wed Oct 16 21:04:44 2013 CST
  16. SMART support is: Available - device has SMART capability.
  17. SMART support is: Enabled
  18. # - 停用 (Disabled)。
  19. $ sudo smartctl -i /dev/sda
  20. smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.8.0-31-generic] (local build)
  21. Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net
  22. === START OF INFORMATION SECTION ===
  23. Device Model: ST3500413AS
  24. Serial Number: Z2AAMWCL
  25. LU WWN Device Id: 5 000c50 035f695b1
  26. Firmware Version: JC45
  27. User Capacity: 500,107,862,016 bytes [500 GB]
  28. Sector Size: 512 bytes logical/physical
  29. Device is: Not in smartctl database [for details use: -P showall]
  30. ATA Version is: 8
  31. ATA Standard is: ATA-8-ACS revision 4
  32. Local Time is: Wed Oct 16 21:05:36 2013 CST
  33. SMART support is: Available - device has SMART capability.
  34. SMART support is: Disabled
  1. 若尚未启用 SMART,可以使用 -s 参数开启它。

  1. $ sudo smartctl -s on /dev/sda
  2. smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.8.0-31-generic] (local build)
  3. Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net
  4. === START OF ENABLE/DISABLE COMMANDS SECTION ===
  5. SMART Enabled.
  1. 支援 SMART 后我们可以使用 -H 参数来手动检查硬盘、随身硬盘的建康状态。

  1. # - 通過 (passed)。
  2. $ sudo smartctl -H /dev/sda
  3. smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.8.0-31-generic] (local build)
  4. Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net
  5. === START OF READ SMART DATA SECTION ===
  6. SMART overall-health self-assessment test result: PASSED
  7. # - 失敗 (failed)。
  8. $ sudo smartctl -H /dev/sda
  9. smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.8.0-31-generic] (local build)
  10. Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net
  11. === START OF READ SMART DATA SECTION ===
  12. SMART overall-health self-assessment test result: FAILED!
  13. Drive failure expected in less than 24 hours. SAVE ALL DATA.
  14. Failed Attributes:
  15. ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
  16. 5 Reallocated_Sector_Ct 0x0033 004 004 005 Pre-fail Always FAILING_NOW 1887

smartd

smartd 是个可以把 smartmontools 注册成例行性服务 (Daemon) 并使用排程来监控的程式,以下为冻仁启用的步骤。

  1. 启用 smartd。

  1. $ sudo vim /etc/default/smartmontools
  2. ...
  3. start_smartd=yes
  4. smartd_opts="--interval=1800"
  1. 备份设定档。

  1. $ sudo cp /etc/smartd.conf /etc/smartd.conf.ori
  1. 编辑设定档。

  1. $ sudo vi /etc/smartd.conf
  2. ......
  3. # 掃描所有的 ATA/SCSI 設備並將報告寄送給 root。
  4. DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner
  5. # 每日 02:00 快速檢查 sda,每週六 03:00 完整檢查 sda。
  6. /dev/sda -a -o on -S on -s (S/../.././02|L/../../6/03)
  7. # 每日 04:00 快速檢查 sdb,每週六 05:00 完整檢查 sdb。
  8. /dev/sdb -a -o on -S on -s (S/../.././04|L/../../6/05)
  9. # 監控 SMART 狀態
  10. /dev/sda -H -l error -l selftest -t -I 194
  11. /dev/sdb -H -l error -l selftest -t -I 194
  12. # 安靜的檢查,並只郵寄建康狀態給 admin@example.tw
  13. /dev/sda -H -C 0 -U 0 -m admin@example.tw
  14. /dev/sdb -H -C 0 -U 0 -m admin@example.tw
  15. ......
  1. 启用服务

  1. $ sudo /etc/init.d/smartmontools start
  1. 观看记录档 (log)。

  1. $ less /var/log/syslog
  2. ......
  3. Oct 17 08:59:47 thinkpad-t410 smartd[11523]: smartd 5.41 2011-06-09 r3365 [x86_64-linux-3.2.0-4-amd64] (local build)
  4. Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net
  5. Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Opened configuration file /etc/smartd.conf
  6. Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Drive: DEVICESCAN, implied '-a' Directive on line 21 of file /etc/smartd.conf
  7. Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Configuration file /etc/smartd.conf was parsed, found DEVICESCAN, scanning devices
  8. Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Device: /dev/sda, type changed from 'scsi' to 'sat'
  9. Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Device: /dev/sda [SAT], opened
  10. ......
  11. Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Device: /dev/sda [SAT], found in smartd database.
  12. Oct 17 08:59:48 thinkpad-t410 smartd[11523]: Device: /dev/sda [SAT], is SMART capable. Adding to "monitor" list.
  13. Oct 17 08:59:48 thinkpad-t410 smartd[11523]: Device: /dev/sda [SAT], state read from /var/lib/smartmontools/smartd.ST9320423AS-5VH55XKG.ata.state
  14. ......
  15. Oct 17 08:59:48 thinkpad-t410 smartd[11525]: smartd has fork()ed into background mode. New PID=11525.
  16. Oct 17 08:59:48 thinkpad-t410 smartd[11525]: file /var/run/smartd.pid written containing PID 11525

※ 若想让 smartd 使用 Gmail 寄送通知件,可使用 sSMTP 来达成。如果能再搭上两步验证里的专属应用程式密码会安全些。

当 SMART 亮起红灯时,请尽速备份并更换硬盘。这时可以先拿先前淘汰的旧硬盘垫挡,否则就赶紧买颗新的补上了! (若您的硬盘保固还没过,那您可以换新硬盘了,恭喜!)

资料来源

  • smartmontools
  • Setting up HDD’s SMART monitoring on Debian Squeeze | Kevin Deldycke
  • Smartmontools - Community Ubuntu Documentation
  • 不自量力 の Weithenn: Smartmontools-检查测试硬盘寿命
  • [Linux] smartctl 使用smartmontools监控硬盘的健康状态 | 70's Blog
  • UbuntuHelp:Smartmontools/zh - Ubuntu中文
  • HDD Health – 硬盘健康状况守护神,有问题马上通知您!! :::iThome Download:::
  • FourDollars Blog: 利用 ssmtp 透过 Gmail 在文字模式下寄信
  • SSMTP - ArchWiki

1

. GNOME Disks 原名为 gnome-disk-utility 和 Palimpsest。在部份的版本中需用 palimpsest 指令来启用磁盘公用程式,例 Debian 7.8。


还没有评论.