马春杰杰 Exit Reader Mode

Mac端自动监控硬盘的S.M.A.R.T.信息

在Mac下想要监控硬盘的S.M.A.R.T.信息还是有很多办法的,很多软件可以办到,比如:

SMART UtilitySoftRAIDDisk Drill不过这些软件都是收费的,另外也比较占资源。这些我都用过,不过感觉Disk Drill并不太准,这个工具主要是恢复数据用的。

我有个盘出现了坏道,上面三个工具中,前两个都能识别,最后一个却显示正常~~

后来决定还是用开源的工具smartmontools

smartmontools-7.1-1

最新版安装之后,路径为:/usr/local/sbin,所以装完之后需要将该目录加到环境变量中,添加方法如下:

添加之后就可以使用了,使用方法为:

smartctl -a /dev/disk0

这样就可以查看disk0S.M.A.R.T.信息:

mcj@mcjdeiMac:~$ smartctl -a /dev/disk0
smartctl 7.1 2019-12-30 r5022 [Darwin 19.3.0 x86_64] (sf-7.1-1)
Copyright (C) 2002-19, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Device Model:     KingBANK KP330
Serial Number:    I23563J002995
LU WWN Device Id: 5 02b2a2 01d1c1b1a
Add. Product Id:  mavlsata
Firmware Version: Q0616A
User Capacity:    120,034,123,776 bytes [120 GB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    Solid State Device
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   ACS-3 T13/2161-D revision 4
SATA Version is:  SATA 3.2, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Wed Dec  2 00:24:55 2020 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:  (0x02)	Offline data collection activity
					was completed without error.
					Auto Offline Data Collection: Disabled.
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: 		(    0) seconds.
Offline data collection
capabilities: 			 (0x35) SMART execute Offline immediate.
					No Auto Offline data collection support.
					Abort Offline collection upon new
					command.
					No Offline surface scan supported.
					Self-test supported.
					Conveyance Self-test supported.
					No Selective Self-test supported.
SMART capabilities:            (0x0002)	Does not save SMART data before
					entering power-saving mode.
					Supports SMART auto save timer.
Error logging capability:        (0x00)	Error logging NOT supported.
					General Purpose Logging supported.
Short self-test routine 
recommended polling time: 	 (   1) minutes.
Extended self-test routine
recommended polling time: 	 (   1) minutes.
Conveyance self-test routine
recommended polling time: 	 (   1) minutes.

SMART Attributes Data Structure revision number: 5
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0
  9 Power_On_Hours          0x0033   100   100   010    Pre-fail  Always       -       20195
 12 Power_Cycle_Count       0x0033   100   100   010    Pre-fail  Always       -       112
161 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       0
164 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       32891
165 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       167
166 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       26
167 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       71
169 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       0
176 Erase_Fail_Count_Chip   0x0033   100   100   010    Pre-fail  Always       -       0
177 Wear_Leveling_Count     0x0033   100   100   010    Pre-fail  Always       -       0
178 Used_Rsvd_Blk_Cnt_Chip  0x0033   100   100   010    Pre-fail  Always       -       0
192 Power-Off_Retract_Count 0x0033   100   100   010    Pre-fail  Always       -       16
194 Temperature_Celsius     0x0033   100   100   010    Pre-fail  Always       -       46
195 Hardware_ECC_Recovered  0x0033   100   100   010    Pre-fail  Always       -       0
199 UDMA_CRC_Error_Count    0x0033   100   100   010    Pre-fail  Always       -       0
241 Total_LBAs_Written      0x0033   100   100   010    Pre-fail  Always       -       11763
242 Total_LBAs_Read         0x0033   100   100   010    Pre-fail  Always       -       8876
243 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       0
244 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       0
245 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       0
246 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       0
250 Read_Error_Retry_Rate   0x0033   100   100   010    Pre-fail  Always       -       0
251 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       0
252 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       0
253 Unknown_Attribute       0x0033   100   100   010    Pre-fail  Always       -       0
254 Unknown_SSD_Attribute   0x0033   100   100   010    Pre-fail  Always       -       0

SMART Error Log not supported

SMART Self-test Log not supported

Selective Self-tests/Logging not supported

如果你看到的不是这么详细的信息,而是短短的:

SMART is disabled

那就应该手动打开:

/usr/local/sbin/smartctl -s on -S on -o on /dev/disk0

之后就是后台监控S.M.A.R.T.信息了:

/dev/disk0 -a -d sat -S on -s (S/../.././02|L/../../6/03)

这里的-d sat是指定你设备的连接类型为SATA,后面指定每天凌晨2点运行一个简短测试,每周六的凌晨3点跑一个长测试,输出的日志会体现在/var/log/system.log里,你可以打开控制台看,也可以自己根据需要用-l参数配置输出到其他地方。这里举例只写了一个设备,有多个设备需要监控的,再加一行就行了。

最后需要注意的是OS X上用LaunchDaemon来启动服务,因此到/Library/LaunchDaemons/下增加一个plist文件吧,plist下载地址见文末。


本文最后更新于2020年12月2日,已超过 1 年没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!