分类: LINUX
2011-02-06 22:32:34
目前市面上所有的硬盘都具有 S.M.A.R.T. (Self-Monitoring, Analysis and Reporting Technology) 特性, 就是利用这一特性监测硬盘的软件包,包含 smartctl 和 smartd 两个程序,前者是前台命令行工具、后者是后台运行程序,smartmontools 不是 Linux 的专利,也支持 BSD, Solaris 等系统。
在 CentOS/Fedora 下安装:
# yum install kernel-utils
在 Debian/Ubuntu 下安装:
# apt-get install smartmontools
在使用 smartmontools 测试之前先检查一下硬盘是否具有 SMART 特性:
# smartctl -i /dev/sda === START OF INFORMATION SECTION === Device Model: SEAGATE ST32500NSSUN250G 0741B58YP8 Serial Number: 5QE58YP8 Firmware Version: 3.AZK User Capacity: 250,056,000,000 bytes Device is: Not in smartctl database [for details use: -P showall] ATA Version is: 7 ATA Standard is: Exact ATA specification draft version not indicated Local Time is: Thu Jul 22 22:39:07 2010 SAST SMART support is: Available - device has SMART capability. SMART support is: Enabled
如果上面 SMART support 是 Disabled 状态的话,需要开启 SMART 的支持:
# smartctl -s on /dev/sda === START OF ENABLE/DISABLE COMMANDS SECTION === SMART Enabled.
检查硬盘状况,如果下面的结果不是 PASSED 的话你需要立刻警觉起来,马上备份所有数据,硬盘随时都可能出问题(不过值得注意的是就算结果是 PASSED 并不意味着硬盘100%就安全,PASS 不能代表没问题,没 PASS 代表一定有问题):
# smartctl -H /dev/sda === START OF READ SMART DATA SECTION === SMART overall-health self-assessment test result: PASSED
做个快速自检:
# smartctl -t short /dev/sda === 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 1 minutes for test to complete. Test will complete after Thu Jul 22 22:51:00 2010 Use smartctl -X to abort test.
执行上面的自检命令后等待一段时间,可以通过下面命令来看进度和结果:
# smartctl -l selftest /dev/sda === 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% 20949 - # 2 Short offline Completed without error 00% 20947 -
要做长时间自检的话(很耗时,建议放在凌晨时间段做):
# smartctl -t long /dev/sda
查看出错日志:
# smartctl -l error /dev/sda === START OF READ SMART DATA SECTION === SMART Error Log Version: 1 No Errors Logged
在 CentOS/Fedora 下:
# vi /etc/smartd.conf # /etc/init.d/smartd restart
在 Debian/Ubuntu 下:
# vi /etc/default/smartmontools # vi /etc/smartd.conf # /etc/init.d/smartmontools restart
可以通过修改以上的 smartmontools 的配置文件来定期对硬盘做健康检查,就像给人定期体检一样,体检过了并不代表就没病(很多疾病用体检的设备都查不到),所以这也符合 Google 的硬盘报告所说的情况,所有坏掉的硬盘中只有60%可以被 S.M.A.R.T. 检测到(所有生病的人中只有60%能在体检的时候发现)。