Software engineering notes

Linux S.M.A.R.T.

S.M.A.R.T.

檢測你的硬碟健康狀態

Installation

sudo apt-get install smartmontools

當硬碟不支援時顯示 Unavailable :

test_user@test-VirtualBox [stp:1] { /var/www  }$ sudo smartctl -i /dev/sda1
smartctl 5.43 2012-06-30 r3573 [x86_64-linux-3.8.0-19-generic] (local build)
Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net

=== START OF INFORMATION SECTION ===
Device Model:     VBOX HARDDISK
Serial Number:    VB47e46d42-bbe471de
Firmware Version: 1.0
User Capacity:    8,589,934,592 bytes [8.58 GB]
Sector Size:      512 bytes logical/physical
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   6
ATA Standard is:  ATA/ATAPI-6 published, ANSI INCITS 361-2002
Local Time is:    Fri May 17 10:08:11 2013 CST
SMART support is: Unavailable - device lacks SMART capability.

To check if the device has SMART capability:

己打開會顯示:

test_user@test { ~  }$ sudo smartctl -i /dev/sda1
smartctl 6.1 2013-03-16 r3800 [x86_64-linux-3.7.4-1-ARCH] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Western Digital RE3 Serial ATA
Device Model:     WDC WD5002ABYS-18B1B0
Serial Number:    WD-WCASY6863830
LU WWN Device Id: 5 0014ee 2ade88ff2
Add. Product Id:  DELL▒
Firmware Version: 02.03B04
User Capacity:    500,107,862,016 bytes [500 GB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    7200 rpm
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ATA8-ACS (minor revision not indicated)
SATA Version is:  SATA 2.5, 3.0 Gb/s
Local Time is:    Mon May 13 13:51:20 2013 CST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

沒打開smart會顯示 Disabled:

test_user@test { /usr/sbin  }$ sudo smartctl -i /dev/sda1
smartctl 6.1 2013-03-16 r3800 [x86_64-linux-3.7.4-1-ARCH] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Western Digital RE3 Serial ATA
Device Model:     WDC WD5002ABYS-18B1B0
Serial Number:    WD-WCASY6863830
LU WWN Device Id: 5 0014ee 2ade88ff2
Add. Product Id:  DELL▒
Firmware Version: 02.03B04
User Capacity:    500,107,862,016 bytes [500 GB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    7200 rpm
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ATA8-ACS (minor revision not indicated)
SATA Version is:  SATA 2.5, 3.0 Gb/s
Local Time is:    Mon May 13 16:04:42 2013 CST
SMART support is: Available - device has SMART capability.
SMART support is: Disabled

If SMART is not enabled, it can be enabled by doing:

打開:

test_user@test { ~  }$ sudo smartctl -s on /dev/sda1
smartctl 6.1 2013-03-16 r3800 [x86_64-linux-3.7.4-1-ARCH] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF ENABLE/DISABLE COMMANDS SECTION ===
SMART Enabled.

沒打開:

test_user@test { /usr/sbin  }$ sudo smartctl -s off /dev/sda1
smartctl 6.1 2013-03-16 r3800 [x86_64-linux-3.7.4-1-ARCH] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF ENABLE/DISABLE COMMANDS SECTION ===
SMART Disabled. Use option -s with argument 'on' to enable it.

check device

test_user@test { ~/test (master) }$ sudo smartctl -P show /dev/sda
smartctl 5.43 2012-06-30 r3573 [x86_64-linux-3.8.0-25-generic] (local build)
Copyright (C) 2002-12 by Bruce Allen, http://smartmontools.sourceforge.net

ATA device successfully opened

Use 'smartctl -a' (or '-x') to print SMART (and more) information

Test the device health :

  1. Short (runs tests that have a high probability of detecting device problems)
  2. Extended (or Long; a short check with complete disk surface examination)
  3. Conveyance (identifies if damage incurred during transportation of the device)

To view the device’s available tests and the time it will take to perform each test do:

打開:

test_user@test { ~  }$ sudo smartctl -c /dev/sda1
smartctl 6.1 2013-03-16 r3800 [x86_64-linux-3.7.4-1-ARCH] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
General SMART Values:
Offline data collection status:  (0x85) Offline data collection activity
                                        was aborted by an interrupting command from host.
                                        Auto Offline Data Collection: Enabled.
Self-test execution status:      ( 248) Self-test routine in progress...
                                        80% of test remaining.
Total time to complete Offline
data collection:                ( 9480) seconds.
Offline data collection
capabilities:                    (0x7b) SMART execute Offline immediate.
                                        Auto Offline 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:        ( 112) minutes.
Conveyance self-test routine
recommended polling time:        (   5) minutes.
SCT capabilities:              (0x303f) SCT Status supported.
                                        SCT Error Recovery Control supported.
                                        SCT Feature Control supported.
                                        SCT Data Table supported.

沒打開會顯示SMART Disabled:

test_user@test { /usr/sbin  }$ sudo smartctl -c /dev/sda1
smartctl 6.1 2013-03-16 r3800 [x86_64-linux-3.7.4-1-ARCH] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
SMART Disabled. Use option -s with argument 'on' to enable it.
(override with '-T permissive' option)

To run the tests do:

smartctl -t short /dev/<device>
smartctl -t long /dev/<device>
smartctl -t conveyance /dev/<device>

Results

To view the test’s overall health status (compiled from all tests):

test_user@test { ~  }$ sudo smartctl -H /dev/sda1
smartctl 6.1 2013-03-16 r3800 [x86_64-linux-3.7.4-1-ARCH] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

PASSED表示硬碟健康狀態良好 Failure表示硬碟有問題

To view the test’s result errors:

test_user@test { ~  }$ sudo smartctl -l selftest /dev/sda1
smartctl 6.1 2013-03-16 r3800 [x86_64-linux-3.7.4-1-ARCH] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
1  Extended offline    Completed without error       00%        95         -
2  Short offline       Completed without error       00%        94         -

To view the test’s detailed results:

sudo smartctl -a /dev/sda1

或使用↓顯示部份資訊

sudo smartctl -A /dev/sda1

If no errors are reported the device is likely healthy. If there are a few errors this may or may not indicate a problem and should be investigated further. When a device starts to fail it is recommended to backup the data and replace it.

ID#

Attribute Name

Flag

Value

Worst

Threshold (THRESH)

Type

Updated

When Failed

Raw Value

狀態:

補充:

參數說明:

中斷背景檢測硬碟:

test_user@test { ~  }$ sudo smartctl -X /dev/sda1
smartctl 6.1 2013-03-16 r3800 [x86_64-linux-3.7.4-1-ARCH] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===
Sending command: "Abort SMART off-line mode self-test routine".
Self-testing aborted!

顯示硬碟錯誤log:

test_user@test { ~  }$ smartctl -l error /dev/sda1
smartctl 6.1 2013-03-16 r3800 [x86_64-linux-3.7.4-1-ARCH] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
Smartctl open device: /dev/sda1 failed: Permission denied
test_user@test { ~  }$ sudo smartctl -l error /dev/sda1
smartctl 6.1 2013-03-16 r3800 [x86_64-linux-3.7.4-1-ARCH] (local build)
Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART Error Log Version: 1
No Errors Logged

-d指定設備類型,例如: ata, scsi, marvell, sat, 3ware,N

$ smartctl -s on -d ata /dev/sdb

disk判斷項目 :

假設 exec() 第3參數為 $is_fail

  1. 有安裝但不支援,$is_fail = 0 (解析第2參數判斷Unavailable)
  2. 有安裝但沒打開,$is_fail = 0 (解析第2參數判斷Disabled)
  3. 沒安裝smart,$is_fail = 1
  4. disk路徑亂打(/devx/sda8),$is_fail = 1 or 127
  5. 指定不存在的disk (/dev/sda8),$is_fail = 2

參考來源:

https://sites.google.com/site/lab586/linuxnote/hddchecktip https://wiki.archlinux.org/index.php/SMART http://space.itpub.net/12823785/viewspace-504042 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 http://southdogs.blogspot.tw/2008/05/smart.html http://www.adminii.com/486.html http://html5.litten.com/accessing-and-assessing-a-hard-drives-s-m-a-r-t-data/ http://sourceforge.net/apps/trac/smartmontools/wiki/Howto_ReadSmartctlReports_ATA