HalNiの雑記

備忘録を兼ねて。サーバマシンとかネットワークとか

smartmontools で MegaRAID 下のHDDからSMARTを取得する ( Linux openSUSE Leap 15.2 )

の記事はopenSUSE Advent Calendar 2020 11日目の記事です。
みなさんこんにちは、HalNi こと Harukaと申します。

MegaRAIDやmdRAIDでのRAIDは、構成ディスクのSMART値の中にある”WHEN_FAILED”のフラグが立った場合にディスクの切り離し・リビルドを行います。

f:id:v_7zrgu0:20201130023734j:plain
mdRAID、MegaRAID共に自動切り離しはしてくれるが…

しかしSMART値で言うところのC7や05、代替処理保留中のセクタ数や代替処理済のセクタ数が他のHDDでもカウントアップしていた場合、リビルド中に他のHDDが飛んでストレージがお亡くなりになることも起こり得ます(起こった)
HDDの早期交換を行うためにも、各ディスクの詳細を把握したい場合、直接ディスクのSMART値を読みに行く必要があります

しかし、以前cazydiskinfoを用いてディスクのSMART値を簡単に閲覧する方法を書きましたが、この方法ではMegaRAIDに接続されているHDD・SSDのSMART値は確認できません 汗
(本家?のCrystalDiskInfoは v8.4.0 でMegaRAIDに対応済み)
この場合、smartmontools を使用してSMART値を確認すれば解決できます。

smartmontools はHDDが提供しているSMART情報を取得するツールですが、オンボードSATAコントローラと同じ感覚でMegaRAIDに繋がっているHDDのSMART値も取得できます。

検証環境:

Supermicro X10SLL-F
MegaRAID 9266-8i
openSUSE Leap 15.2

おうちの検証(にも使う)環境
おうちサーバは大部分がopenSUSEで稼働しています

f:id:v_7zrgu0:20201011030222j:plain
2020年10月現在のおうち環境。そろそろHDD積み鯖の世代更新をしたい

openSUSE では smartmontools はパッケージとして配布されています。

haruka@SUSE-X10SLL:~> zypper search smartmontools
Repository 'Main Update Repository' is out-of-date. You can run 'zypper refresh' as root to update it.
Loading repository data...
Reading installed packages...

S | Name          | Summary                   | Type
--+---------------+---------------------------+--------
i | smartmontools | Monitor for SMART devices | package
haruka@SUSE-X10SLL:~>

基本的には smartmontools はデフォルトでインストールされているはずです
入っていない場合は openSUSE の場合 sudo zypper install smartmontools で導入できます。

smartmontoolsが動いているか確認、デーモンのstatusを見ればわかります

systemctl status smartd

haruka@SUSE-X10SLL:~> systemctl status smartd
● smartd.service - Self Monitoring and Reporting Technology (SMART) Daemon
   Loaded: loaded (/usr/lib/systemd/system/smartd.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2020-10-08 07:55:57 JST; 3 days ago
     Docs: man:smartd(8)
           man:smartd.conf(5)
 Main PID: 1134 (smartd)
    Tasks: 1
   CGroup: /system.slice/smartd.service
           └─1134 /usr/sbin/smartd -n
haruka@SUSE-X10SLL:~>    

active になっていればOK

接続されているディスクを検索します

sudo smartctl --scan

haruka@SUSE-X10SLL:~> sudo smartctl --scan
/dev/sda -d scsi # /dev/sda, SCSI device
/dev/sdb -d scsi # /dev/sdb, SCSI device
/dev/sdc -d scsi # /dev/sdc, SCSI device
/dev/bus/0 -d megaraid,0 # /dev/bus/0 [megaraid_disk_00], SCSI device
/dev/bus/0 -d megaraid,1 # /dev/bus/0 [megaraid_disk_01], SCSI device
/dev/bus/0 -d megaraid,2 # /dev/bus/0 [megaraid_disk_02], SCSI device
/dev/bus/0 -d megaraid,3 # /dev/bus/0 [megaraid_disk_03], SCSI device
/dev/bus/0 -d megaraid,14 # /dev/bus/0 [megaraid_disk_14], SCSI device
/dev/bus/0 -d megaraid,15 # /dev/bus/0 [megaraid_disk_15], SCSI device
/dev/bus/0 -d megaraid,16 # /dev/bus/0 [megaraid_disk_16], SCSI device
/dev/bus/0 -d megaraid,17 # /dev/bus/0 [megaraid_disk_17], SCSI device
haruka@SUSE-X10SLL:~>

論理ディスクの下に出てくる /dev/bus/0 にあるのが物理ディスクです。
手元環境はMegaRAIDに計8台HDDを繋いでいるため、8台分リストアップされています。

ここでMegaRAID下のHDDを参照する場合、引数としてデバイスタイプを明示する必要があります。
-d の後にコントローラ(今回はMegaRAID)とすればOK

smartctl --info /dev/bus/0 -d megaraid,ディスク番号
ディスクの情報が取得できます

sudo smartctl --info /dev/bus/0 -d megaraid,14

haruka@SUSE-X10SLL:~> sudo smartctl --info /dev/bus/0 -d megaraid,14
smartctl 7.0 2019-05-21 r4917 [x86_64-linux-5.3.18-lp152.19-default] (SUSE RPM)
Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Hitachi Deskstar 7K1000
Device Model:     Hitachi HDS721010KLA330
Serial Number:    **********
LU WWN Device Id: 5 000cca 21ed35ddc
Firmware Version: GKAOAB0A
User Capacity:    1,000,204,886,016 bytes [1.00 TB]
Sector Size:      512 bytes logical/physical
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ATA/ATAPI-7 T13/1532D revision 1
Local Time is:    Sun Oct 11 14:26:22 2020 JST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

haruka@SUSE-X10SLL:~>

sudo smartctl -A /dev/bus/0 -d megaraid,ディスク番号
これでsmart値を確認できます。

sudo smartctl -A /dev/bus/0 -d megaraid,14

haruka@SUSE-X10SLL:~> sudo smartctl -A /dev/bus/0 -d megaraid,14
smartctl 7.0 2019-05-21 r4917 [x86_64-linux-5.3.18-lp152.19-default] (SUSE RPM)
Copyright (C) 2002-18, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
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   130   130   054    Pre-fail  Offline      -       150
  3 Spin_Up_Time            0x0007   105   105   024    Pre-fail  Always       -       656 (Average 665)
  4 Start_Stop_Count        0x0012   100   100   000    Old_age   Always       -       39
  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   132   132   020    Pre-fail  Offline      -       33
  9 Power_On_Hours          0x0012   095   095   000    Old_age   Always       -       38221
 10 Spin_Retry_Count        0x0013   100   100   060    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       34
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       360
193 Load_Cycle_Count        0x0012   100   100   000    Old_age   Always       -       360
194 Temperature_Celsius     0x0002   162   162   000    Old_age   Always       -       37 (Min/Max 17/47)
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

haruka@SUSE-X10SLL:~>

crystaldiskinfoは16進数だが smartctlでは 10進数で表記されています
よって C5 "代替処理保留中のセクタ数" を参照する場合は 197 を参照すればOK

VALUE や RAW_VALUE の値を読むと、このHDDは4万時間弱通電しているのか、などということが分かります

当たり前ですがSSDも参照できます。

haruka@SUSE-RX2540:~> sudo smartctl --info /dev/bus/1 -d megaraid,2
smartctl 6.6 2017-11-05 r4594 [x86_64-linux-4.12.14-lp151.28.67-default] (SUSE RPM)
Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Vendor:               SEAGATE
Product:              ST100FM0002
Revision:             FT03
User Capacity:        100,030,242,816 bytes [100 GB]
Logical block size:   512 bytes
LB provisioning type: not reported [LBPME=1, LBPRZ=1]
Rotation Rate:        Solid State Device
Form Factor:          2.5 inches
Logical Unit id:      0x5000c5003010c48f
Serial number:        **********
Device type:          disk
Transport protocol:   SAS (SPL-3)
Local Time is:        Sun Oct 11 03:07:22 2020 JST
SMART support is:     Available - device has SMART capability.
SMART support is:     Enabled
Temperature Warning:  Disabled or Not Supported

haruka@SUSE-RX2540:~> sudo smartctl -A /dev/bus/1 -d megaraid,2
smartctl 6.6 2017-11-05 r4594 [x86_64-linux-4.12.14-lp151.28.67-default] (SUSE RPM)
Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
Current Drive Temperature:     38 C
Drive Trip Temperature:        65 C

Manufactured in week 13 of year 2013
Specified cycle count over device lifetime:  10000
Accumulated start-stop cycles:  95
Vendor (Seagate) cache information
  Blocks sent to initiator = 2384575137
  Blocks received from initiator = 3146259547
  Blocks read from cache and sent to initiator = 256
  Number of read and write commands whose size <= segment size = 310239021
  Number of read and write commands whose size > segment size = 119138

Vendor (Seagate/Hitachi) factory information
  number of hours powered up = 49094.47
  number of minutes until next internal SMART test = 33

haruka@SUSE-RX2540:~>

SAS接続の Seagate製 100GB SSD からも正常に情報を読めている (FUJITSU RX2540 M2, EP420i, openSUSE Leap 15.1 )

こんな記事をのうのうと書いていたら、まさにMegaRAID下のHDDが一台Failしたという…
FailしたHDDのSMARTはこんな感じ

haruka@SUSE-TX200:~> sudo smartctl --info /dev/sdd -d sat
smartctl 6.6 2017-11-05 r4594 [x86_64-linux-4.12.14-lp151.28.59-default] (SUSE RPM)
Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Device Model:     ST8000NM0055-1RM112
Serial Number:    ZA16DXZE
LU WWN Device Id: 5 000c50 0a1d77924
Firmware Version: SN02
User Capacity:    8,001,563,222,016 bytes [8.00 TB]
Sector Sizes:     512 bytes logical, 4096 bytes physical
Rotation Rate:    7200 rpm
Form Factor:      3.5 inches
Device is:        Not in smartctl database [for details use: -P showall]
ATA Version is:   ACS-3 T13/2161-D revision 5
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Sun Oct 11 19:42:29 2020 JST
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

haruka@SUSE-TX200:~> sudo smartctl -A /dev/sdd -d sat
smartctl 6.6 2017-11-05 r4594 [x86_64-linux-4.12.14-lp151.28.59-default] (SUSE RPM)
Copyright (C) 2002-17, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===
SMART Attributes Data Structure revision number: 10
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  1 Raw_Read_Error_Rate     0x000f   039   039   044    Pre-fail  Always   FAILING_NOW 6416884
  3 Spin_Up_Time            0x0003   089   088   000    Pre-fail  Always       -       0
  4 Start_Stop_Count        0x0032   099   099   020    Old_age   Always       -       1958
  5 Reallocated_Sector_Ct   0x0033   074   074   010    Pre-fail  Always       -       40320 (0 1)
  7 Seek_Error_Rate         0x000f   092   060   045    Pre-fail  Always       -       1761493702
  9 Power_On_Hours          0x0032   072   072   000    Old_age   Always       -       25310 (218 229 0)
 10 Spin_Retry_Count        0x0013   100   100   097    Pre-fail  Always       -       0
 12 Power_Cycle_Count       0x0032   100   100   020    Old_age   Always       -       64
184 End-to-End_Error        0x0032   100   100   099    Old_age   Always       -       0
187 Reported_Uncorrect      0x0032   017   017   000    Old_age   Always       -       83
188 Command_Timeout         0x0032   084   084   000    Old_age   Always       -       146031116387
189 High_Fly_Writes         0x003a   100   100   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0022   063   046   040    Old_age   Always       -       37 (Min/Max 35/37)
191 G-Sense_Error_Rate      0x0032   099   099   000    Old_age   Always       -       2404
192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       274
193 Load_Cycle_Count        0x0032   029   029   000    Old_age   Always       -       142179
194 Temperature_Celsius     0x0022   037   054   000    Old_age   Always       -       37 (0 16 0 0 0)
195 Hardware_ECC_Recovered  0x001a   068   064   000    Old_age   Always       -       6416884
197 Current_Pending_Sector  0x0012   100   100   000    Old_age   Always       -       0
198 Offline_Uncorrectable   0x0010   100   100   000    Old_age   Offline      -       0
199 UDMA_CRC_Error_Count    0x003e   200   200   000    Old_age   Always       -       0
240 Head_Flying_Hours       0x0000   100   253   000    Old_age   Offline      -       19618 (150 159 0)
241 Total_LBAs_Written      0x0000   100   253   000    Old_age   Offline      -       16454446061
242 Total_LBAs_Read         0x0000   100   253   000    Old_age   Offline      -       2141289580391

haruka@SUSE-TX200:~>

ID :1 Raw_Read_Error_Rate WHEN_FAILED が FAILING_NOW になっているのが分かるかと思います。

因みにこのHDDを CrystalDiskInfo で見るとこんな感じ

f:id:v_7zrgu0:20201011195203j:plain
赤!


自動監視を行う場合、 Reallocated_Sector_Ct や Current_Pending_Sector の生の値を定期的に見てあげたら良さそうです。
ということで異常が発生した時にSlackでアラートを飛ばしてくれるスクリプトを適当に書いたのでよければどうぞ
crontabとかで定期的に実行してあげると良いかも?

github.com

実行したサーバのHDDに不良セクタが発生した場合、こんな感じに通知が飛んできます

f:id:v_7zrgu0:20201204142455j:plain
35個もあるんかよ、というツッコミは無しで


やはりSMART値の監視は大事やね (

参考文献

wiki.archlinux.jp

www.smartmontools.org