RAID1構成のHDD2台のうち1台が故障したようなので実施した対処をご報告です。
以前に構成したRaspberry PiのUSBハードディスクで発生しました。
対象の環境
以前にRaspberry Piで構成したsambaサーバ、データ用に外付けHDDをUSB経由で接続し、RAID1をmdadmで構成していました。
■RaspberryPiの外付けHDDでソフトウェアRAID1
https://blog.treedown.net/entry/2016/09/07/010000
このディスクで障害が発生、対処を実施することになりました。
状況
きっかけは、mdadm monitoringからのアラートメール。表題に「Fail event on /dev/md0:%ServerNAME%」の記載がありました。
サーバ名は仮にfssvr2とします。
--------------------------------------------------------------
Fail event on /dev/md0:fssvr2
--------------------------------------------------------------
This is an automatically generated mail message from mdadm running on fssvr2
A Fail event had been detected on md device /dev/md0.
It could be related to component device /dev/sdb1.
Faithfully yours, etc.
P.S. The /proc/mdstat file currently contains the following:
Personalities : [raid1]
md0 : active raid1 sdb1[0](F) sdc1[1]
78089728 blocks super 1.2 [2/1] [_U]
[>....................] check = 1.1% (874496/78089728) finish=42155.3min speed=30K/sec
unused devices: <none>
--------------------------------------------------------------
このアラートメールの後で、
--------------------------------------------------------------
DegradedArray event on /dev/md0:fssvr2
--------------------------------------------------------------
This is an automatically generated mail message from mdadm running on fssvr2
A DegradedArray event had been detected on md device /dev/md0.
Faithfully yours, etc.
P.S. The /proc/mdstat file currently contains the following:
Personalities : [raid1]
md0 : active raid1 sdb1[0](F) sdc1[1]
78089728 blocks super 1.2 [2/1] [_U]
unused devices: <none>
--------------------------------------------------------------
「DegradedArray」となっています。sdb1に(F)が付いているので、/dev/sdbのHDDが故障してしまったと判断しました。
SSHで接続しmdstatで確認してみると
このようにRAID1の片方のHDDがFailしているのが分かりました。
HDD交換作業
問題の起きたHDDを切り離すため
# mdadm /dev/md0 --fail /dev/sdb1
# mdadm /dev/md0 --remove /dev/sdb1
を実行します。が、どうも「DegradedArray」発生時点でfailしていたみたい。(※mdstatで(F)が付加されていたのがそれっぽい)
前回別のサーバで実施したときは、正常動作していたほう(今回は/dev/sdc1)のディスクもデュプリケータでバックアップしていたのですが、今回時間の関係から割愛。(でも時間に余裕があるようならやっておいたほうが良いかも)
故障したほうのハードディスク本体を特定し、外付けUSBハードディスクのケースから故障ディスクを取り出して、正常動作が確認出来ている予備ハードディスクと交換します。(※USB接続だとシリアル番号の確認とか出来ないこともあるから、ちょっと不便)
交換後、リビルド作業前に…
HDD交換後、再度起動してアレイmd0の状態を確認します。
-------------------------------------------------------
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[1]
78089728 blocks super 1.2 [2/1] [_U]
unused devices: <none>
-------------------------------------------------------
sdb1が正常状態で片方のみの稼働となっています。ん?と思いましたが、どうやら/dev/sdcだったのが/dev/sdbになって、故障時に/dev/sdbだったディスクは/dev/sdaになったようでした。(dmesgやfdisk -lで確認)
例えば、fdisk -lの実行結果から(抜粋)
-------------------------------------------------------
Disk /dev/sda: 74.5 GiB, 80032038912 bytes, 156312576 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sdb: 74.5 GiB, 80032038912 bytes, 156312576 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x26372548
Device Boot Start End Sectors Size Id Type
/dev/sdb1 2048 156312575 156310528 74.5G fd Linux raid autodetect
Disk /dev/md0: 74.5 GiB, 79963881472 bytes, 156179456 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdb1[1]
78089728 blocks super 1.2 [2/1] [_U]
unused devices: <none>
-------------------------------------------------------
80GBのHDDを示す「74.5 GiB」が「/dev/sda」と「/dev/sdb」に表示されています。一方で、ディスクとして認識している表記なのは/dev/sdb側で/dev/sda側にはDisklabel typeやDeviceの列挙(md0のLinux raid箇所)にそのエントリがありません。
新しく追加したHDDが「/dev/sda」なのは間違いない、と確認できたので、さっそく「/dev/sda」をmd0アレイに参加させるための準備をしていきます。
パーティション作成
まずはアレイmd0にディスクを追加する前にパーティションを作成します。80GBという少量なのでfdiskコマンドで実行可能。コマンドは「fdisk /dev/sda」を実行。
-------------------------------------------------------
# fdisk /dev/sda
Welcome to fdisk (util-linux 2.29.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0xfde4f206.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-156312575, default 2048): 2048
Last sector, +sectors or +size{K,M,G,T,P} (2048-156312575, default 156312575): 156312575
Created a new partition 1 of type 'Linux' and of size 74.5 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
-------------------------------------------------------
今回は、
■RaspberryPiの外付けHDDでソフトウェアRAID1
https://blog.treedown.net/entry/2016/09/07/010000
で実施したfdiskコマンドと全く同じ操作でハードディスク内にパーティションを作成していきます。
簡単に解説。(自分用のメモともいう)
「Command (m for help): 」で「n」で押下(new Partitionの意味、多分)
Partition typeを聞かれるので「Select (default p): 」で「p」(※デフォルトと同じ)を選択。
「Partition number (1-4, default 1): 」では「1」(一番最初のパーティション)
「First sector (2048-156312575, default 2048): 」では「2048」(デフォルトと同じ)
「Last sector, +sectors or +size{K,M,G,T,P} (2048-156312575, default 156312575): 」では「156312575」(これもデフォルトと同じ)
First sectorからLast sectorで指定した容量がパーティションとして確保されます。
メッセージ
「Created a new partition 1 of type 'Linux' and of size 74.5 GiB.」
が表示されたら正常完了。
最後に、
「Command (m for help): 」にて「w」を入力して、指定したパーティション構成を実際にハードディスクに書き込み(保存)して終了します。
これで
# fdisk -l
すると、
-------------------------------------------------------
Disk /dev/sda: 74.5 GiB, 80032038912 bytes, 156312576 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xfde4f206
Device Boot Start End Sectors Size Id Type
/dev/sda1 2048 156312575 156310528 74.5G 83 Linux
-------------------------------------------------------
/dev/sdaの情報表示が、パーティションを作成した後の状況に代わりました。
リビルト作業
交換したHDDにパーティションを作成したところで、実際のリビルド作業に入ります。
パーティションを作成した状態では「Type」欄が「Linux」となっていて、sdbの様に「Linux raid autodetect」にはなっていません。リビルドでこうなります。
今回実行するコマンドは
# mdadm /dev/md0 --add /dev/sda1
になります。
さっそく実行。
「mdadm: added /dev/sda1」と表示され、アレイにハードディスクが追加されたようでした。
さっそく「cat /proc/mdstat」で確認。
-------------------------------------------------------
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sda1[2] sdb1[1]
78089728 blocks super 1.2 [2/1] [_U]
[>....................] recovery = 0.2% (216768/78089728) finish=95.7min speed=13548K/sec
unused devices: <none>
-------------------------------------------------------
いい反応です。しばらくすると、0.2%となっている箇所が、1.0%⇒2.8%と増えていきました。1分で1%処理が完了するくらいのペースでした。
しばらく待つと
-------------------------------------------------------
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sda1[2] sdb1[1]
78089728 blocks super 1.2 [2/1] [_U]
[=============>.......] recovery = 65.8% (51429568/78089728) finish=30.5min speed=14564K/sec
unused devices: <none>
-------------------------------------------------------
ここまで来たらエラーは出ないだろうと判断し、ひとまず現地作業を完了させました。
最終的に、
-------------------------------------------------------
# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sda1[2] sdb1[1]
78089728 blocks super 1.2 [2/2] [UU]
unused devices: <none>
-------------------------------------------------------
無事RAID1の復旧を完了することができました。