在FreeBSD Linux上如何检查硬盘的健康状况

时间:2019-11-20 08:53:42  来源:igfitidea点击:

在Linux中,如何检查硬盘的状态?
在FreeBSD Linux上,如何对硬盘进行健康检查?
如何使用smartctl命令读取硬盘的运行状况?
如何在FreeBSD上安装smartmontools?

解决方案

现代的硬盘一般都内置了SMART系统(Self-Monitoring, Analysis, and Reporting Technology System),即自我监控,分析和报告技术系统。

在FreeBSD上安装smartmontools

使用FreeBSD ports进行安装:

# cd /usr/ports/sysutils/smartmontools
# make install clean

或者使用pkg命令安装二进制包:

# pkg install smartmontools

smartmontools软件包中包含了两个实用程序:

  • smartctl命令 用于控制和监视硬盘的运行状况。
  • smartd 这是一个守护程序,它监视硬盘的运行状况并向用户发出有关问题的警报。

在FreeBSD上如何检查硬盘的健康状况

检查驱动器的状态语法如下:

smartctl -a /dev/disk

首先在FreeBSD中查看所有连接到系统的硬盘:

# camcontrol devlist

或者从启动日志中查找:

# egrep 'ad[0-9]|cd[0-9]' /var/run/dmesg.boot
egrep 'da[0-9]|cd[0-9]' /var/run/dmesg.boot

FreeeBSD检查硬盘的健康状况

查看硬盘的信息

# smartctl -i /dev/ada0

输出示例:

smartctl 7.0 2018-12-30 r4883 [FreeBSD 11.2-RELEASE-p10 amd64] (local build)
Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org
 
=== START OF INFORMATION SECTION ===
Model Family:     Western Digital Red
Device Model:     WDC WD60EFRX-68MYMN1
Serial Number:    WD-XXXXXXXXXXXXXXX
LU WWN Device Id: 5 0014ee 26195240d
Firmware Version: 82.00A82
User Capacity:    6,001,175,126,016 bytes [6.00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    5700 rpm
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ACS-2, ACS-3 T13/2161-D revision 3b
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Mon May 20 22:53:06 2019 IST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

检查磁盘运行状况,运行:

# smartctl -a /dev/ada0

输出示例:

smartctl 7.0 2018-12-30 r4883 [FreeBSD 11.2-RELEASE-p10 amd64] (local build)
Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org
 
=== START OF INFORMATION SECTION ===
Model Family:     HGST Deskstar NAS
Device Model:     HGST YYYYYYYYYZZZ
Serial Number:    K1JVDUGD
LU WWN Device Id: 5 000cca 255e830c9
Firmware Version: APGNW7JH
User Capacity:    6,001,175,126,016 bytes [6.00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    7200 rpm
Form Factor:      3.5 inches
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ACS-2, ATA8-ACS T13/1699-D revision 4
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Mon May 20 23:00:59 2019 IST
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
 
 
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     0x000b   100   100   016    Pre-fail  Always       -       0
  2 Throughput_Performance  0x0005   138   138   054    Pre-fail  Offline      -       100
  3 Spin_Up_Time            0x0007   149   149   024    Pre-fail  Always       -       436 (Average 449)
  4 Start_Stop_Count        0x0012   100   100   000    Old_age   Always       -       43
  5 Reallocated_Sector_Ct   0x0033   100   100   005    Pre-fail  Always       -       0
  7 Seek_Error_Rate         0x000b   100   100   067    Pre-fail  Always       -       0
  8 Seek_Time_Performance   0x0005   128   128   020    Pre-fail  Offline      -       18
  9 Power_On_Hours          0x0012   099   099   000    Old_age   Always       -       8501
10 Spin_Retry_Count        0x0013   100   100   060    Pre-fail  Always       -       0
12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       42
192 Power-Off_Retract_Count 0x0032   095   095   000    Old_age   Always       -       6673
193 Load_Cycle_Count        0x0012   095   095   000    Old_age   Always       -       6673
194 Temperature_Celsius     0x0002   117   117   000    Old_age   Always       -       51 (Min/Max 25/52)
196 Reallocated_Event_Count 0x0032   100   100   000    Old_age   Always       -       0
197 Current_Pending_Sector  0x0022   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0008   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x000a   200   200   000    Old_age   Always       -       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.

如何配置Smartd发送电子邮件警报

编辑文件:

# cd /usr/local/etc
# cp smartd.conf.sample smartd.conf
# vim smartd.conf

注释掉或删除所有DEVICESCAN行:

# DEVICESCAN

设置要监视的设备。例如:

/dev/ada0 -a -m disk.admin@your-tld

也添加所有磁盘:

/dev/ada1 -a -m disk.admin@your-tld,root@localhost

确保smartd在引导时启动:

echo 'smartd_enable="YES"' >> /etc/rc.conf

如何启动/停止/重启smartd服务

# service smartd start
# service smartd restart
# service smartd status
# service smartd stop