oracle support換硬碟,檢測硬碟 SMART 健康狀態

本文介绍了如何在Linux系统中使用smartmontools工具来检查和监控硬盘的S.M.A.R.T.健康状态。通过安装smartmontools套件,使用smartctl进行一次性扫描和启用SMART功能,以及配置smartd作为后台服务定期监控硬盘,可以及时发现硬盘潜在问题,确保数据安全。
摘要由CSDN通过智能技术生成

# 完全用 GNU/Linux 工作

### 29. 檢測硬碟 S.M.A.R.T. 健康狀態

[S.M.A.R.T.](http://zh.wikipedia.org/wiki/S.M.A.R.T.) 是個用來檢測硬碟健康狀況的指標,雖然前文 [26. 使用 Clonezilla 打造不死的作業系統](#) 提供了軟體層面的備份方式,但硬體總有老舊、損壞的一天。而一台電腦中又以硬碟裡的資料最為重要,這裡凍仁將介紹 GNU/Linux 下檢測、監控的方法。

![2013-10-16-palimpsest-smart.png](https://box.kancloud.cn/2015-08-18_55d2bbb32ea42.png "2013-10-16-palimpsest-smart.png")

▲ 在 GNOME 上我們可使用 [磁碟公用程式 (GNOME Disks)](http://en.wikipedia.org/wiki/GNOME_Disks)[1](#) 來檢測 SMART。

### 安裝 smartmontools

套件 smartmontools 包含了 smartctl, smartd,是個可以監控 ATA, SCSI 硬碟 (storage) SMART (Self-Monitoring, Analysis and Reporting Technology System) 狀態的工具。我們可以透過它來進階設定各種硬碟退化、錯誤警告的回報機制。

安裝文字介面的檢測工具 smartmontools。

~~~

# Debian, Ubuntu

$ sudo aptitude install smartmontools

# CentOS, RHEL, Fedora

$ sudo yum install smartmontools

~~~

### smartctl

smartctl 主要是用來進行一次性、暫時性的硬碟掃描,以下為常見的使用方法。

1.

查看該媒體是否支援 SMART 檢測。

~~~

# - 啟用 (Enabled)。

$ sudo smartctl -i /dev/sda

smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.8.0-31-generic] (local build)

Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF INFORMATION SECTION ===

Device Model: ST3500413AS

Serial Number: Z2AAMWCL

LU WWN Device Id: 5 000c50 035f695b1

Firmware Version: JC45

User Capacity: 500,107,862,016 bytes [500 GB]

Sector Size: 512 bytes logical/physical

Device is: Not in smartctl database [for details use: -P showall]

ATA Version is: 8

ATA Standard is: ATA-8-ACS revision 4

Local Time is: Wed Oct 16 21:04:44 2013 CST

SMART support is: Available - device has SMART capability.

SMART support is: Enabled

# - 停用 (Disabled)。

$ sudo smartctl -i /dev/sda

smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.8.0-31-generic] (local build)

Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF INFORMATION SECTION ===

Device Model: ST3500413AS

Serial Number: Z2AAMWCL

LU WWN Device Id: 5 000c50 035f695b1

Firmware Version: JC45

User Capacity: 500,107,862,016 bytes [500 GB]

Sector Size: 512 bytes logical/physical

Device is: Not in smartctl database [for details use: -P showall]

ATA Version is: 8

ATA Standard is: ATA-8-ACS revision 4

Local Time is: Wed Oct 16 21:05:36 2013 CST

SMART support is: Available - device has SMART capability.

SMART support is: Disabled

~~~

1.

若尚未啟用 SMART,可以使用 *-s* 參數開啟它。

~~~

$ sudo smartctl -s on /dev/sda

smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.8.0-31-generic] (local build)

Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF ENABLE/DISABLE COMMANDS SECTION ===

SMART Enabled.

~~~

1.

支援 SMART 後我們可以使用 *-H* 參數來手動檢查硬碟、隨身硬碟的建康狀態。

~~~

# - 通過 (passed)。

$ sudo smartctl -H /dev/sda

smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.8.0-31-generic] (local build)

Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF READ SMART DATA SECTION ===

SMART overall-health self-assessment test result: PASSED

# - 失敗 (failed)。

$ sudo smartctl -H /dev/sda

smartctl 5.41 2011-06-09 r3365 [x86_64-linux-3.8.0-31-generic] (local build)

Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF READ SMART DATA SECTION ===

SMART overall-health self-assessment test result: FAILED!

Drive failure expected in less than 24 hours. SAVE ALL DATA.

Failed Attributes:

ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE

5 Reallocated_Sector_Ct 0x0033 004 004 005 Pre-fail Always FAILING_NOW 1887

~~~

### smartd

smartd 是個可以把 smartmontools 註冊成例行性服務 (Daemon) 並使用排程來監控的程式,以下為凍仁啟用的步驟。

1.

啟用 smartd。

~~~

$ sudo vim /etc/default/smartmontools

...

start_smartd=yes

smartd_opts="--interval=1800"

~~~

1.

備份設定檔。

~~~

$ sudo cp /etc/smartd.conf /etc/smartd.conf.ori

~~~

1.

編輯設定檔。

~~~

$ sudo vi /etc/smartd.conf

......

# 掃描所有的 ATA/SCSI 設備並將報告寄送給 root。

DEVICESCAN -d removable -n standby -m root -M exec /usr/share/smartmontools/smartd-runner

# 每日 02:00 快速檢查 sda,每週六 03:00 完整檢查 sda。

/dev/sda -a -o on -S on -s (S/../.././02|L/../../6/03)

# 每日 04:00 快速檢查 sdb,每週六 05:00 完整檢查 sdb。

/dev/sdb -a -o on -S on -s (S/../.././04|L/../../6/05)

# 監控 SMART 狀態

/dev/sda -H -l error -l selftest -t -I 194

/dev/sdb -H -l error -l selftest -t -I 194

# 安靜的檢查,並只郵寄建康狀態給 admin@example.tw

/dev/sda -H -C 0 -U 0 -m admin@example.tw

/dev/sdb -H -C 0 -U 0 -m admin@example.tw

......

~~~

1.

啟用服務

~~~

$ sudo /etc/init.d/smartmontools start

~~~

1.

觀看記錄檔 (log)。

~~~

$ less /var/log/syslog

......

Oct 17 08:59:47 thinkpad-t410 smartd[11523]: smartd 5.41 2011-06-09 r3365 [x86_64-linux-3.2.0-4-amd64] (local build)

Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Copyright (C) 2002-11 by Bruce Allen, http://smartmontools.sourceforge.net

Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Opened configuration file /etc/smartd.conf

Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Drive: DEVICESCAN, implied '-a' Directive on line 21 of file /etc/smartd.conf

Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Configuration file /etc/smartd.conf was parsed, found DEVICESCAN, scanning devices

Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Device: /dev/sda, type changed from 'scsi' to 'sat'

Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Device: /dev/sda [SAT], opened

......

Oct 17 08:59:47 thinkpad-t410 smartd[11523]: Device: /dev/sda [SAT], found in smartd database.

Oct 17 08:59:48 thinkpad-t410 smartd[11523]: Device: /dev/sda [SAT], is SMART capable. Adding to "monitor" list.

Oct 17 08:59:48 thinkpad-t410 smartd[11523]: Device: /dev/sda [SAT], state read from /var/lib/smartmontools/smartd.ST9320423AS-5VH55XKG.ata.state

......

Oct 17 08:59:48 thinkpad-t410 smartd[11525]: smartd has fork()ed into background mode. New PID=11525.

Oct 17 08:59:48 thinkpad-t410 smartd[11525]: file /var/run/smartd.pid written containing PID 11525

~~~

※ 若想讓 smartd 使用 Gmail 寄送通知件,可使用 [sSMTP](https://wiki.debian.org/sSMTP) 來達成。如果能再搭上兩步驗證裡的專屬應用程式密碼會安全些。

當 SMART 亮起紅燈時,請儘速備份並更換硬碟。這時可以先拿先前淘汰的舊硬碟墊擋,否則就趕緊買顆新的補上了! (若您的硬碟保固還沒過,那您可以換新硬碟了,恭喜!)

### 資料來源

- [smartmontools](http://sourceforge.net/apps/trac/smartmontools/wiki)

- [Setting up HDD’s SMART monitoring on Debian Squeeze | Kevin Deldycke](http://kevin.deldycke.com/2011/05/setting-hdds-smart-monitoring-debian-squeeze/)

- [Smartmontools - Community Ubuntu Documentation](https://help.ubuntu.com/community/Smartmontools)

- [不自量力 の Weithenn: Smartmontools-檢查測試硬碟壽命](http://www.weithenn.org/cgi-bin/wiki.pl?Smartmontools-%E6%AA%A2%E6%9F%A5%E6%B8%AC%E8%A9%A6%E7%A1%AC%E7%A2%9F%E5%A3%BD%E5%91%BD)

- [[Linux] smartctl 使用smartmontools監控硬碟的健康狀態 | 70's Blog](http://70tw.spotlight.net.tw/?p=330)

- [UbuntuHelp:Smartmontools/zh - Ubuntu中文](http://zoomq.qiniudn.com/ZQScrapBook/ZqFLOSS/data/20090924194150/)

- [HDD Health – 硬碟健康狀況守護神,有問題馬上通知您!! :::iThome Download:::](http://download.ithome.com.tw/article/index/id/326)

- [FourDollars Blog: 利用 ssmtp 透過 Gmail 在文字模式下寄信](http://fourdollars.blogspot.tw/2009/08/ssmtp-gmail.html)

- [SSMTP - ArchWiki](https://wiki.archlinux.org/index.php/SSMTP)

1

> . GNOME Disks 原名為 gnome-disk-utility 和 Palimpsest。在部份的版本中需用 palimpsest 指令來啟用磁碟公用程式,例 Debian 7.8。

[ ↩](# "Jump back to footnote [1] in the text.")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值