Linux查看硬盘分区及健康状况fdisk、df、smartctl2009-08-04 11:01Linux查看硬盘分区及健康状况fdisk、df、smartctl
koudai.360/u/13434790/article_211653970.html
bbs.51cto/thread-509964-1.html
hi.baidu/chuanqi_ding/blog/item/fe7eea35d6d5221990ef3949.html
fdisk可以查看硬盘分区、格式
fdisk 是一款强大的磁盘操作工具,来自util-linux软件包,我们在这里只说他如何查看磁盘分区表及分区结构;通过-l 参数,能获得机器中所有的硬盘的分区情况;
[root@localhost etc]# fdisk -l
Disk /dev/sda: 640.1 GB, 640135028736 bytes
255 heads, 63 sectors/track, 77825 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 19 152586 83 Linux
/dev/sda2 20 1294 10241437+ 83 Linux
/dev/sda3 1295 3844 20482875 83 Linux
/dev/sda4 3845 77825 594252382+ 5 Extended
/dev/sda5 3845 6394 20482843+ 83 Linux
/dev/sda6 6395 7414 8193118+ 82 Linux swap / Solaris
/dev/sda7 7415 77825 565576326 83 Linux
[root@localhost etc]#
df查看硬盘使用情况及系统挂在位置
df 是来自于coreutils 软件包,系统安装时自带;我们通过这个命令可以查看磁盘的使用情况以及文件系统被挂载的位置;
[root@localhost etc]# df -l
文件系统 1K-块 已用 可用
已用% 挂载点
/dev/sda2 9920624 4851060 4557496 52% /
/dev/sda7 547856836 199925444 319652576 39% /opt
/dev/sda5 19840892 802320 18014432 5% /var
/dev/sda3 19840924 1464976 17351808 8% /usr/local
/dev/sda1 147764 11127 129008 8% /boot
tmpfs 1033032 0 1033032 0% /dev/shm
[root@localhost etc]#
smartctl可以检查硬盘健康状况
[root@localhost etc]# smartctl -a /dev/sda -d ata
smartctl version 5.36 [i686-redhat-linux-gnu] Copyright (C) 2002-6 Bruce Allen
Home page is smartmontools.sourceforge/
=== START OF INFORMATION SECTION ===
Device Model: WDC WD6400AAKS-22A7B0
Serial Number: WD-WCASY0701341
Firmware Version: 01.03B01
User Capacity: 640,135,028,736 bytes
Device is: Not in smartctl database [for details use: -P showall]
ATA Version is: 8
ATA Standard is: Exact ATA specification draft version not indicated
Local Time is: Fri Jul 31 14:51:11 2009 CST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
General SMART Values:
Offline data collection status: (0x84) Offline data collection activity
was suspended by an interrupting command from host.
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: (11580) seconds.
Offline data collection
capabilities: (0x7b) SMART execute Offline immediate.
Auto O
ffline data collection on/off support.
Suspend Offline collection upon new
command.
Offline surface scan supported.
Self-test supported.
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: ( 2) minutes.
Extended self-test routine
recommended polling time: ( 136) minutes.
Conveyance self-test routine
recommended polling time: ( 5) minutes.
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 200 200 051 Pre-fail Always - 0
3 Spin_Up_Time 0x0027 156 156 021 Pre-fail Always - 5166
4 Start_Stop_Count 0x0032 100 100 000 Old_age Always - 120
5 Reallocated_Sector_Ct 0x0033 200 200 140 Pre-fail Always - 0
7 Seek_Error_Rate 0x002e 200 200 051 Old_age Always - 0
9 Power_On_Hours 0x0032 091 091 000 Old_age Always - 6779
10 Spin_Retry_Count 0x0032 100 100 051 Old_age Always - 0
11 Calibration_Retry_Count 0x0032 100 100 051 Old_age Always - 0
12 Power_Cycle_Count 0x0032 100 100 000 Old_age Always - 119
192 Power-Off_Retract_Count 0x0032 200 200 000 Old_age Always - 17
193 Load_Cycle_Count 0x0032 200 200 000 Old_age Always - 120
194 Temperature_Celsius 0x0022 100 096 000 Old_age Always - 47
196 Reallocated_Event_Count 0x0032 200 200 000 Old_age Always - 0
197 Current_Pending_Sector 0x0032 200 200 000 Old_age Always - 0
198 Offline_Uncorrectable 0x0030 100 253 000 Old_age Offline - 0
199 UDMA_CRC_Error_Count 0x0032 200 200 000 Old_age Always - 0
200 Multi_Zone_Error_Rate 0x0008 100 253 051 Old_age Offline - 0
SMART Error Log Version: 1
No Errors Logged
SMART Self-test log structure revision number 1
No self-tests have been logged. [To run self-tests, use: smartctl -t]
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.
[root@localhost etc]#
在Linux上启动S.M.A.R.T.硬盘检测
启用SMART
SMART是和主板BIOS上相应功能配合的
要使用SMART,必须先进入到主板BIOS设置里边启动相关设置
一般从Pentium2级别起的主板,都支持SMART
BIOS启动以后,就是操作系统级别的事情了
很遗憾,Windows没有内置SMART相关工具(需要安装第三方工具软件)
好在Linux上很早就有了SMART支持了
如果把Linux装在VMware等虚拟机上,
在系统启动时候可以看到有个服务启动报错:smartd
这个服务器就是smart的daemon进程(因为vmware虚拟机的硬盘不支持SMART,所以报错)
首先通过dmesg工具,确认一下硬盘的设备符号
例如一个IDE硬盘连接到Primary IDE 总线上的Slave位置,硬盘设备符号是/dev/hdb
hdb中的h代表IDE,如果显示为sdb,则代表SATA和SCSI
最后一个字幕b代表Primary总线,第二块硬盘即Slave位置
确认硬盘是否打开了SMART支持
smartctl -i /dev/hdb
例如看到如下返回结果
[root@3.6.0Biz-46 ~]# smartctl -i /dev/hdb
smartctl version 5.33 [i386-redhat-linux-gnu] Copyright (C) 2002-4 Bruce Allen
Home page is smartmontools.sourceforge/
=== START OF INFORMATION SECTION ===
Device Model: ST380011A
Serial Number: 3JVAPRGH
Firmware Version: 3.04
User Capacity: 80,026,361,856 bytes
Device is: In smartctl database [for details use: -P show]
ATA Version is: 6
ATA Standard is: ATA/ATAPI-6 T13 1410D revision 2
Local Time is: Tue Apr 3 15:39:52 2007 CST
SMART support is: Available - device has SMART capability.
SMART support is: Disabled
SMART Disabled. Use option -s with argument 'on' to enable it.
[root@3.6.0Biz-46 ~]#
例如,我们从下边可以看到SMART support is: Disabled表示SMART未启用
执行如下命令,启动SMART:
smartctl --smart=on --offlineauto=on --saveauto=on /dev/hdb
例如看到如下返回结果
[root@3.6.0Biz-46 ~]# smartctl --smart=on --offlineauto=on --saveauto=on /dev/hdb
smartctl version 5.33 [i386-redhat-linux-gnu] Copyright (C) 2002-4 Bruce Allen
Home page is smartmontools.sourceforge/
=== START OF ENABLE/DISABLE COMMANDS SECTION ===
SMART Enabled.
SMART Attribute Autosave Enabled.
SMART Automatic Offline Testing Enabled every four hours.
[root@3.6.0Biz-46 ~]#
现在硬盘的SMART功能已经被打开
执行如下命令查看硬盘的健康状况:
smartctl -H /dev/hda
例如可以看到如下结果:
[root@3.6.0Biz-46 ~]# smartctl -H /dev/hdb
smartctl version 5.33 [i386-redhat-linux-gnu] Copyright (C) 2002-4 Bruce Allen
Home page is smartmontools.sourceforge/
=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED
[root@3.6.0Biz-46 ~]#
请注意result后边的结果:PASSED,这表示硬盘健康状态良好
如果这里显示Failure,那么最好立刻给服务器更换硬盘
SMART只能报告磁盘已经不再健康,但是报警后还能继续运行多久是不确定的
通常,SMART报警参数是有预留的,磁盘报警后,不会当场坏掉,一般能坚持一段时间
有的硬盘SMART报警后还继续跑了好几年,有的硬盘SMART报错后几天就坏了
但是一旦出现报警,侥幸心里是万万不能的……
执行如下命令可以看到详细的参数:
smartctl -A /dev/hdb
例如可以看到如下结果:
[root@3.6.0Biz-
46 ~]# smartctl -A /dev/hdb
smartctl version 5.33 [i386-redhat-linux-gnu] Copyright (C) 2002-4 Bruce Allen
Home page is smartmontools.sourceforge/
=== START OF READ SMART DATA SECTION ===
linux磁盘管理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 053 051 006 Pre-fail Always - 11338710
3 Spin_Up_Time 0x0003 098 097 000 Pre-fail Always - 0
4 Start_Stop_Count 0x0032 100 100 020 Old_age Always - 17
5 Reallocated_Sector_Ct 0x0033 100 100 036 Pre-fail Always - 0
7 Seek_Error_Rate 0x000f 087 060 030 Pre-fail Always - 610059516
9 Power_On_Hours 0x0032 087 087 000 Old_age Always - 11974
10 Spin_Retry_Count 0x0013 100 100 097 Pre-fail Always - 0
12 Power_Cycle_Count 0x0032 100 100 020 Old_age Always - 110
194 Temperature_Celsius 0x0022 045 052 000 Old_age Always - 45
195 Hardware_ECC_Recovered 0x001a 053 051 000 Old_age Always - 11338710
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 200 000 Old_age Always - 0
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
[root@3.6.0Biz-46 ~]#
上边列出的参数表中可供进行技术分析和参考,使用下边的命令可以输出完整结果:
smartctl -a /dev/hdb
定期登录到服务器上运行smartctl是比较麻烦的,linux提供了系统进程smartd
编辑配置文件:
vi /f
这个配置文件中大部分可能是注释掉的说明,只需要和当前硬盘相关的一行写入正确即可:
/
dev/hdb -H -m [url=mailto:test@test123123]test@test123123[/url]
上边的配置表示smartd以静默状态工作,当SMART中报告PASSED的时候不理睬
一旦出现Failure,立刻用邮件通知用户指定的邮箱
修改配置后重启服务:
/etc/init.d/smartd
即可完成对SMART的全部配置。