用Smartmontools(Debian&Ubuntu)检查硬盘的真实性
版本1.0
作者:Falko Timme
本指南介绍如何在Debian Etch和Ubuntu 7.10上安装和使用smartmontools软件包。 smartmontools软件包使用内置于大多数现代ATA和SCSI硬盘中的自我监控,分析和报告技术系统(SMART)来提供实用程序来检查硬盘是否有磁盘退化和故障。
我不会保证这将为您工作!
1安装Smartmontools
为了安装smartmontools,我们要做的就是运行:
apt-get install smartmontools
smartmontools软件包带有两个可用于在命令行上检查硬盘驱动器的smartctl
, smartd
是一个以指定的间隔检查硬盘的守护进程,并将警告/错误记录到syslog中,并且还可以发送警告并将错误发送到指定的电子邮件地址(通常是系统的管理员)。
2使用Smartctl
在我们可以使用smartctl
之前,我们必须弄清楚我们的硬盘是如何命名的。 你可以这样做,例如,运行:
df -h
要么
fdisk -l
server1:~# fdisk -l
Disk /dev/hda: 160.0 GB, 160041885696 bytes
255 heads, 63 sectors/track, 19457 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 19269 154778211 83 Linux
/dev/hda2 19270 19457 1510110 5 Extended
/dev/hda5 19270 19457 1510078+ 82 Linux swap / Solaris
server1:~#
如您所见,我的硬盘称为/ dev / hda
。
现在我们知道硬盘的名称,我们可以运行smartctl
,如下所示:
smartctl -a /dev/hda
如果你第一次运行它,你可能会看到这样的东西:
server1:~# smartctl -a /dev/hda
smartctl version 5.36 [i686-pc-linux-gnu] Copyright (C) 2002-6 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF INFORMATION SECTION ===
Device Model: ST3160022ACE
Serial Number: 5JS3XTZX
Firmware Version: 9.01
User Capacity: 160,041,885,696 bytes
Device is: Not in smartctl database [for details use: -P showall]
ATA Version is: 6
ATA Standard is: ATA/ATAPI-6 T13 1410D revision 2
Local Time is: Tue Apr 8 18:58:44 2008 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Disabled
SMART Disabled. Use option -s with argument 'on' to enable it.
server1:~#
所以SMART被禁用,为了启用它,我们需要再次使用-s on
switch来运行该命令:
smartctl -s on -a /dev/hda
现在我们得到更多的输出,包括SMART日志中的所有错误(如果有):
server1:~# smartctl -s on -a /dev/hda
smartctl version 5.36 [i686-pc-linux-gnu] Copyright (C) 2002-6 Bruce Allen
Home page is http://smartmontools.sourceforge.net/
=== START OF INFORMATION SECTION ===
Device Model: ST3160022ACE
Serial Number: 5JS3XTZX
Firmware Version: 9.01
User Capacity: 160,041,885,696 bytes
Device is: Not in smartctl database [for details use: -P showall]
ATA Version is: 6
ATA Standard is: ATA/ATAPI-6 T13 1410D revision 2
Local Time is: Tue Apr 8 18:59:14 2008 CEST
SMART support is: Available - device has SMART capability.
SMART support is: Disabled
=== START OF ENABLE/DISABLE COMMANDS SECTION ===
SMART Enabled.
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
General SMART Values:
Offline data collection status: (0x82) Offline data collection activity
was completed without error.
Auto Offline Data Collection: Enabled.
Self-test execution status: ( 0) The previous self-test routine completed
without error or no self-test has ever
been run.
Total time to complete Offline
data collection: (15556) seconds.
Offline data collection
capabilities: (0x5b) SMART execute Offline immediate.
Auto Offline data collection on/off support.
Suspend Offline collection upon new
command.
Offline surface scan supported.
Self-test supported.
No Conveyance Self-test supported.
Selective Self-test supported.
SMART capabilities: (0x0003) Saves SMART data before entering
power-saving mode.
Supports SMART auto save timer.
Error logging capability: (0x01) Error logging supported.
General Purpose Logging supported.
Short self-test routine
recommended polling time: ( 1) minutes.
Extended self-test routine
recommended polling time: ( 111) minutes.
SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
1 Raw_Read_Error_Rate 0x000f 059 056 006 Pre-fail Always - 163692057
3 Spin_Up_Time 0x0003 096 096 000 Pre-fail Always - 0
4 Start_Stop_Count 0x0032 100 100 020 Old_age Always - 0
5 Reallocated_Sector_Ct 0x0033 100 100 036 Pre-fail Always - 0
7 Seek_Error_Rate 0x000f 100 253 030 Pre-fail Always - 722959
9 Power_On_Hours 0x0032 100 100 000 Old_age Always - 55
10 Spin_Retry_Count 0x0013 100 100 097 Pre-fail Always - 0
12 Power_Cycle_Count 0x0032 100 100 020 Old_age Always - 37
194 Temperature_Celsius 0x0022 039 046 000 Old_age Always - 39
195 Hardware_ECC_Recovered 0x001a 059 056 000 Old_age Always - 163692057
197 Current_Pending_Sector 0x0012 100 100 000 Old_age Always - 0
198 Offline_Uncorrectable 0x0010 100 100 000 Old_age Offline - 0
199 UDMA_CRC_Error_Count 0x003e 200 199 000 Old_age Always - 1
200 Multi_Zone_Error_Rate 0x0000 100 253 000 Old_age Offline - 0
202 TA_Increase_Count 0x0032 100 253 000 Old_age Always - 0
SMART Error Log Version: 1
ATA Error Count: 1
CR = Command Register [HEX]
FR = Features Register [HEX]
SC = Sector Count Register [HEX]
SN = Sector Number Register [HEX]
CL = Cylinder Low Register [HEX]
CH = Cylinder High Register [HEX]
DH = Device/Head Register [HEX]
DC = Device Command Register [HEX]
ER = Error register [HEX]
ST = Status register [HEX]
Powered_Up_Time is measured from power on, and printed as
DDd+hh:mm:SS.sss where DD=days, hh=hours, mm=minutes,
SS=sec, and sss=millisec. It "wraps" after 49.710 days.
Error 1 occurred at disk power-on lifetime: 28 hours (1 days + 4 hours)
When the command that caused the error occurred, the device was active or idle.
After command completion occurred, registers were:
ER ST SC SN CL CH DH
-- -- -- -- -- -- --
84 51 00 5d 4c 85 e0 Error: ICRC, ABRT at LBA = 0x00854c5d = 8735837
Commands leading to the command that caused the error were:
CR FR SC SN CL CH DH DC Powered_Up_Time Command/Feature_Name
-- -- -- -- -- -- -- -- ---------------- --------------------
25 00 00 5d 4c 85 e0 00 05:05:31.855 READ DMA EXT
25 00 00 5d 4b 85 e0 00 05:05:31.810 READ DMA EXT
25 00 00 5d 4a 85 e0 00 05:05:31.773 READ DMA EXT
25 00 00 5d 49 85 e0 00 05:05:31.737 READ DMA EXT
25 00 00 5d 48 85 e0 00 05:05:31.651 READ DMA EXT
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% 54 -
# 2 Short offline Aborted by host 80% 54 -
# 3 Short offline Completed without error 00% 54 -
SMART Selective self-test log data structure revision number 1
SPAN MIN_LBA MAX_LBA CURRENT_TEST_STATUS
1 0 0 Not_testing
2 0 0 Not_testing
3 0 0 Not_testing
4 0 0 Not_testing
5 0 0 Not_testing
Selective self-test flags (0x0):
After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.
server1:~#
现在SMART已启用,我们不再需要-s
开关,这意味着您可以像第一个示例中一样调用smartctl
。
要了解更多关于smartctl
以及如何使用它,请查看smartctl
手册页:
man smartctl
3使用Smartd
Smartctl是一个不错的工具,但您必须手动运行它。 当然,有一些守护进程会按照指定的时间间隔监视我们的硬盘,如果硬盘有问题,可以使用日志和/或电子邮件给我们,以便在完全失败之前做出反应。 Smartd就是我们所需要的。
要使用smartd
,我们必须首先修改/ etc / default / smartmontools
,并取消注释start_smartd = yes
和smartd_opts =“ - interval = 1800”
行(将监视间隔设置为您喜欢的任何值(以秒为单位); 1800表示30分钟):
vi /etc/default/smartmontools
# Defaults for smartmontools initscript (/etc/init.d/smartmontools) # This is a POSIX shell fragment # List of devices you want to explicitly enable S.M.A.R.T. for # Not needed (and not recommended) if the device is monitored by smartd #enable_smart="/dev/hda /dev/hdb" # uncomment to start smartd on system startup start_smartd=yes # uncomment to pass additional options to smartd on startup smartd_opts="--interval=1800" |
接下来,我们必须配置smartd
配置文件/etc/smartd.conf
。 你应该看看
man smartd
了解有关可用配置选项的更多信息,并查看/etc/smartd.conf中的示例。
vi /etc/smartd.conf
对于开始,以下配置很好:
DEVICESCAN -m root -M exec /usr/share/smartmontools/smartd-runner |
DEVICESCAN
意味着smartd
将监控所有可以找到的硬盘。 -m
开关指定smartd
将发送警告/错误的用户或电子邮件地址。 例如,要仅监视/ dev / hda
并向admin@example.com
发送警告/错误,请改用以下配置:
/dev/hda -m admin@example.com -M exec /usr/share/smartmontools/smartd-runner |
之后我们启动smartd
:
/etc/init.d/smartmontools start
现在,如果你看看/ var / log / syslog
,你应该找到smartd
的启动消息:
tail -n50 /var/log/syslog
[...]
Apr 8 19:12:17 server1 smartd[3731]: smartd version 5.36 [i686-pc-linux-gnu] Copyright (C) 2002-6 Bruce Allen
Apr 8 19:12:17 server1 smartd[3731]: Home page is http://smartmontools.sourceforge.net/
Apr 8 19:12:17 server1 smartd[3731]: Opened configuration file /etc/smartd.conf
Apr 8 19:12:17 server1 smartd[3731]: Drive: DEVICESCAN, implied '-a' Directive on line 22 of file /etc/smartd.conf
Apr 8 19:12:17 server1 smartd[3731]: Configuration file /etc/smartd.conf was parsed, found DEVICESCAN, scanning devices
Apr 8 19:12:17 server1 smartd[3731]: Problem creating device name scan list
Apr 8 19:12:17 server1 smartd[3731]: Device: /dev/hda, opened
Apr 8 19:12:17 server1 smartd[3731]: Device: /dev/hda, not found in smartd database.
Apr 8 19:12:17 server1 smartd[3731]: Device: /dev/hda, is SMART capable. Adding to "monitor" list.
Apr 8 19:12:17 server1 smartd[3731]: Device: /dev/hdc, opened
Apr 8 19:12:17 server1 smartd[3731]: Device: /dev/hdc, packet devices [this device CD/DVD] not SMART capable
Apr 8 19:12:17 server1 smartd[3731]: Monitoring 1 ATA and 0 SCSI devices
Apr 8 19:12:17 server1 smartd[3733]: smartd has fork()ed into background mode. New PID=3733.
Apr 8 19:12:17 server1 smartd[3733]: file /var/run/smartd.pid written containing PID 3733
[...]
如果smartd
发现有关您的硬盘或错误/警告的内容,还会记录这些事件,例如:
Apr 8 19:36:01 server2 smartd[13160]: Device: /dev/hda, SMART Usage Attribute: 194 Temperature_Celsius changed from 36 to 37
(这当然不是错误或警告,只是一些有趣的事情。)
如果您告诉smartd
这样做,错误和警告也将发送到用户/电子邮件地址。
4链接
- Smartmontools: http : //smartmontools.sourceforge.net