如何在FreeBSD上检查硬盘的健康状况
时间:2020-01-09 14:16:54 来源:igfitidea点击:
如何在FreeBSD操作系统上使用smartctl命令读取硬盘/SSD的运行状况?
如何在FreeBSD上对硬盘进行健康检查,并确定我的磁盘是否快要死了?
大多数现代硬盘都内置了自我监视,分析和报告技术系统(SMART)。
SMART的目的是监视硬盘驱动器的可靠性并预测驱动器故障,并在FreeBSD操作系统下执行不同类型的驱动器自检。
在本教程中我们学习了如何在FreeBSD上安装smartmontools以及如何使用smartcl在FreeBSD上检查硬盘的运行状况。
在FreeBSD上安装smartmontools
使用FreeBSD ports系统,如下进行安装:
# cd /usr/ports/sysutils/smartmontools # make install clean
或者一个可以二进制打包的系统。
运行以下pkg命令:
# pkg install smartmontools
使用pkg在FreeBSD上安装smartmontools
smartmontools软件包包含用于FreeBSD的两个实用程序:
- smartctl命令一种命令行工具,用于控制和监视硬盘的运行状况。
- smartd这是一个FreeBSD守护程序,它监视硬盘的运行状况并使用日志文件,电子邮件等向用户发出有关问题的警报。
如何在FreeBSD上检查硬盘的健康状况
语法如下以检查驱动器的状态:
smartctl -a /dev/disk
通过运行以下命令,可以获取FreeBSD中所有已连接硬盘的列表:
# camcontrol devlist
或按以下方式使用grep命令/egrep命令:
# egrep 'ad[0-9]|cd[0-9]' /var/run/dmesg.boot egrep 'da[0-9]|cd[0-9]' /var/run/dmesg.boot
FreeBSD列出了所有连接的物理设备和逻辑单元
FreeeBSD硬盘健康状况检查
现在您知道在FreeBSD上命名的硬盘设备。
因此,是时候检查硬盘信息了,运行:
# smartctl -i /dev/ada0
输出示例:
smartctl 7.0 2016-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 2016-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以获得电子邮件警报
使用vim命令如下编辑文件:
# 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.conf手册页。
确保smartd在引导时启动,运行:
echo 'smartd_enable="YES"' >> /etc/rc.conf
启动/停止/重新启动服务
# service smartd start # service smartd restart # service smartd status # service smartd stop