287 瀏覽數

Linux command – smartctl

之前有透過 #hdparm 或是 /sys/class/sas_phy/phy-0\:0/maximum_linkrate 是檢視 硬碟 SATA / SAS Link Speed http://benjr.tw/80914

root@ubuntu:~# cat /sys/class/sas_phy/phy-4\:0/maximum_linkrate
3.0 Gbit

同事推薦我可以用 smartctl 直接看更快,這是透過硬碟本身所提供的 S.M.A.R.T. (Self-Monitoring Analysis and Reporting Technology )技術 ,他可以根據檢測屬性的結果來決定該顆硬碟的使用是否快故障.

測試環境為 Ubuntu14.04 ,預設是沒有安裝 smart 的工具.

root@ubuntu:~# apt-get install smartmontools

常用的參數

  • -H, –health

    root@ubuntu:~# smartctl -H /dev/sdb
    smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-24-generic] (local build)
    Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
    
    === START OF READ SMART DATA SECTION ===
    SMART Health Status: OK
    
  • -i, –info

    root@ubuntu:~# smartctl -i /dev/sdb
    smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-24-generic] (local build)
    Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
    
    === START OF INFORMATION SECTION ===
    Vendor:               IBM-ESXS
    Product:              MBB2147RC
    Revision:             SB04
    User Capacity:        146,814,976,000 bytes [146 GB]
    Logical block size:   512 bytes
    Rotation Rate:        10025 rpm
    Logical Unit id:      0x500000e01d93f8c0
    Serial number:        BS59P8A04LRL
    Device type:          disk
    Transport protocol:   SAS
    Local Time is:        Tue Nov  1 15:37:24 2016 CST
    SMART support is:     Available - device has SMART capability.
    SMART support is:     Enabled
    Temperature Warning:  Enabled
    
  • -t TEST, –test=TEST

    這邊會列出可供測試的項目.

    root@ubuntu:~# smartctl -t /dev/sdb
    smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-24-generic] (local build)
    Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
    
    =======> INVALID ARGUMENT TO -t: /dev/sdb
    =======> VALID ARGUMENTS ARE: offline, short, long, conveyance, force, vendor,N, select,M-N, pending,N, afterselect,[on|off] =======
    
    Use smartctl -h to get a usage summary
    

    來試試看 short , long 測試,測試會在背景執行,需要透過 -l selftest 來觀看目前的測試進度與結果.

    root@ubuntu:~# smartctl -t short /dev/sdb
    smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-24-generic] (local build)
    Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
    
    Short Background Self Test has begun
    Use smartctl -X to abort test
    
    root@ubuntu:~# smartctl -t long /dev/sdb
    smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-24-generic] (local build)
    Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
    
    Extended Background Self Test has begun
    Please wait 34 minutes for test to complete.
    Estimated completion time: Tue Nov  1 16:15:59 2016
    
    Use smartctl -X to abort test
    
    root@ubuntu:~# smartctl -l selftest /dev/sdb
    smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-24-generic] (local build)
    Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
    
    === START OF READ SMART DATA SECTION ===
    Self-test execution status:		96% of test remaining
    SMART Self-test log
    Num  Test              Status                 segment  LifeTime  LBA_first_err [SK ASC ASQ]
         Description                              number   (hours)
    # 1  Background long   Self test in progress ...   -     NOW                 - [-   -    -]
    # 2  Background short  Completed                   -   19184                 - [-   -    -]
    Long (extended) Self Test duration: 2040 seconds [34.0 minutes]
    
  • -l TYPE, –log=TYPE

    -l 除了剛剛看到的 selftest 外還有不同的參數 error, selftest, selective, directory[,g|s], xerror[,N][,error], xselftest[,N][,selftest], background, sasphy[,reset], sataphy[,reset], scttemp[sts,hist], scttempint,N[,p], scterc[,N,M], devstat[,N], ssd, gplog,N[,RANGE], smartlog,N[,RANGE] 可以指定使用.

    root@ubuntu:~# smartctl -l /dev/sdb
    smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-24-generic] (local build)
    Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
    
    =======> INVALID ARGUMENT TO -l: /dev/sdb
    =======> VALID ARGUMENTS ARE: error, selftest, selective, directory[,g|s], xerror[,N][,error], xselftest[,N][,selftest], background, sasphy[,reset], sataphy[,reset], scttemp[sts,hist], scttempint,N[,p], scterc[,N,M], devstat[,N], ssd, gplog,N[,RANGE], smartlog,N[,RANGE] <=======
    
    Use smartctl -h to get a usage summary
    

    -l error 可以檢測該顆硬碟的 Error count (Errors Corrected by ECC fast | delayed , Errors Corrected by rereads / rewrites , Total errors corrected , Correction algorithm invocations , Total uncorrected errors)

    root@ubuntu:~# smartctl -l error /dev/sdb
    smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-24-generic] (local build)
    Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
    
    === START OF READ SMART DATA SECTION ===
    Error counter log:
               Errors Corrected by           Total   Correction     Gigabytes    Total
                   ECC          rereads/    errors   algorithm      processed    uncorrected
               fast | delayed   rewrites  corrected  invocations   [10^9 bytes]  errors
    read:          0        0         0         0          0     123263.011           0
    write:         0        0         0         0          0       5218.671           0
    verify:        0        0         0         0          0         24.721           0
    
    Non-medium error count:      148
    

    透過 -l sasphy 就可以檢視 SAS 硬碟 Link Speed (SATA 指令為 sataphy)

    root@ubuntu:~# smartctl -l sasphy /dev/sdb
    smartctl 6.2 2013-07-26 r3841 [x86_64-linux-3.13.0-24-generic] (local build)
    Copyright (C) 2002-13, Bruce Allen, Christian Franke, www.smartmontools.org
    
    === START OF READ SMART DATA SECTION ===
    Protocol Specific port log page for SAS SSP
    relative target port id = 1
      generation code = 0
      number of phys = 1
      phy identifier = 0
        attached device type: end device
        attached reason: unknown
        reason: unknown
        negotiated logical link rate: phy enabled; 3 Gbps
        attached initiator port: ssp=1 stp=1 smp=1
        attached target port: ssp=0 stp=0 smp=0
        SAS address = 0x500000e01d93f8c2
        attached SAS address = 0x5005076b06400f25
        attached phy identifier = 1
        Invalid DWORD count = 2686
        Running disparity error count = 473
        Loss of DWORD synchronization = 1
        Phy reset problem = 0
    relative target port id = 2
      generation code = 0
      number of phys = 1
      phy identifier = 1
        attached device type: no device attached
        attached reason: unknown
        reason: unknown
        negotiated logical link rate: phy enabled; unknown
        attached initiator port: ssp=0 stp=0 smp=0
        attached target port: ssp=0 stp=0 smp=0
        SAS address = 0x500000e01d93f8c3
        attached SAS address = 0x0
        attached phy identifier = 0
        Invalid DWORD count = 0
        Running disparity error count = 0
        Loss of DWORD synchronization = 0
        Phy reset problem = 0
    
  • -a, –all

    -a 對於 ATA 硬碟參數等同 , ‘-H -i -c -A -l error -l selftest -l selective’
    -a 對於 SCSI 硬碟參數等同 , ‘-H -i -A -l error -l selftest’

  • -x, –xall

    -x 對於 ATA 硬碟參數等同 , ‘-H -i -g all -c -A -f brief -l xerror,error -l xselftest,selftest -l selective -l directory -l scttemp -l scterc -l sataphy’.
    -x 對於 SCSI 硬碟參數等同 , ‘-H -i -A -l error -l selftest -l background -l sasphy’.

  • smartd

    我們可以透過 smartd Daemon 讓他自動監視硬碟的狀態.設定請參考 http://benjr.tw/96013

  • GSmartControl

    不習慣使用指令方式的還有圖形介面可以使用,須額外安裝 GSmartControl

2 個網友的想法 “Linux command – smartctl

  1. 自動參照通知: Linux command – smartctl (-t) – Benjr.tw

  2. 自動參照通知: Linux – smartd – Benjr.tw

發表迴響