4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ubuntu 14.04でのraid1作成、復旧手順(その2)

Posted at

その2です。
今回は実際にHDDを一個壊してみたいと思います。
色々なサイトを眺めてると、フラグを立てて実験とか書いてありますが、せっかくなのでVirtualBoxからすぱっとHDDを取り除いてみたいと思います。

まずは正常な状態

root@raidtest:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sdb1[1] sda1[0]
      8382400 blocks super 1.2 [2/2] [UU]

unused devices: <none>
root@raidtest:~#
root@raidtest:~# mdadm --detail /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Wed May 20 10:54:43 2015
     Raid Level : raid1
     Array Size : 8382400 (7.99 GiB 8.58 GB)
  Used Dev Size : 8382400 (7.99 GiB 8.58 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Wed May 20 12:27:29 2015
          State : clean
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : raidtest:0  (local to host raidtest)
           UUID : 72ce48ed:e3135c0d:5605621c:a94999e7
         Events : 19

    Number   Major   Minor   RaidDevice State
       0       8        1        0      active sync   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1

それでは一度停止して、sdaの方をVirtualBoxから取り除いてみたいと思います。
SATA ポート0の方のHDDを抜いたら sdaが残ったので失敗。。。
(番号が若い方からsda sdbかと思ってた。。。)
で、SATA ポート0を付けたらよくわからない状態に。。。

root@raidtest:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sdb1[1]
      8382400 blocks super 1.2 [2/1] [_U]

unused devices: <none>
root@raidtest:~# mdadm --detail /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Wed May 20 10:54:43 2015
     Raid Level : raid1
     Array Size : 8382400 (7.99 GiB 8.58 GB)
  Used Dev Size : 8382400 (7.99 GiB 8.58 GB)
   Raid Devices : 2
  Total Devices : 1
    Persistence : Superblock is persistent

    Update Time : Wed May 20 12:35:54 2015
          State : clean, degraded
 Active Devices : 1
Working Devices : 1
 Failed Devices : 0
  Spare Devices : 0

           Name : raidtest:0  (local to host raidtest)
           UUID : 72ce48ed:e3135c0d:5605621c:a94999e7
         Events : 109

    Number   Major   Minor   RaidDevice State
       0       0        0        0      removed
       1       8       17        1      active sync   /dev/sdb1

とりあえず sdb1がアクティブですよー 片肺ですよー って状態になりました。
カーネルログを見ると

[    2.867813] md: bind<sda1>
[    2.875037] md: kicking non-fresh sda1 from array!
[    2.875886] md: unbind<sda1>
[    2.877474] md: export_rdev(sda1)

mdのbindに失敗とよく見ると、mdadmのログが

    Number   Major   Minor   RaidDevice State
       0       0        0        0      removed
       1       8       17        1      active sync   /dev/sdb1

すでにNumber0になにかあったけど removedしたよー と
ということで、sdaを追加するだけでいいのかなぁ?

sdbのパーテション状態の確認

root@raidtest:~# parted /dev/sdb
GNU Parted 2.3
/dev/sdb を使用
GNU Parted へようこそ! コマンド一覧を見るには 'help' と入力してください。
(parted) print
モデル: ATA VBOX HARDDISK (scsi)
ディスク /dev/sdb: 8590MB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: msdos

番号  開始    終了    サイズ  タイプ   ファイルシステム  フラグ
 1    1049kB  8589MB  8588MB  primary                    boot, raid

これと同じ設定にsdaを設定

root@raidtest:~# parted /dev/sda
GNU Parted 2.3
/dev/sda を使用
GNU Parted へようこそ! コマンド一覧を見るには 'help' と入力してください。
(parted) print
モデル: ATA VBOX HARDDISK (scsi)
ディスク /dev/sda: 8590MB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: msdos

番号  開始  終了  サイズ  タイプ  ファイルシステム  フラグ

(parted) mkpart
パーティションの種類?  primary/プライマリ/extended/拡張? primary
ファイルシステムの種類?  [ext2]?
開始? 1049kB
終了? 8589MB
(parted) print
モデル: ATA VBOX HARDDISK (scsi)
ディスク /dev/sda: 8590MB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: msdos

番号  開始    終了    サイズ  タイプ   ファイルシステム  フラグ
 1    1049kB  8590MB  8589MB  primary

(parted) set 1 boot on
(parted) set 1 raid on
(parted) print
モデル: ATA VBOX HARDDISK (scsi)
ディスク /dev/sda: 8590MB
セクタサイズ (論理/物理): 512B/512B
パーティションテーブル: msdos

番号  開始    終了    サイズ  タイプ   ファイルシステム  フラグ
 1    1049kB  8590MB  8589MB  primary                    boot, raid

うん、サイズをちょっと間違えたけどなんとなく同じようにできました。
作成したパーテションを/dev/md0に追加

root@raidtest:~# mdadm /dev/md0 --add /dev/sda1
mdadm: added /dev/sda1

状況の確認

root@raidtest:~# cat /proc/mdstat
Personalities : [linear] [multipath] [raid0] [raid1] [raid6] [raid5] [raid4] [raid10]
md0 : active raid1 sda1[2] sdb1[1]
      8382400 blocks super 1.2 [2/1] [_U]
      [==>..................]  recovery = 11.0% (928960/8382400) finish=7.3min speed=16926K/sec

unused devices: <none>
root@raidtest:~# mdadm --detail /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Wed May 20 10:54:43 2015
     Raid Level : raid1
     Array Size : 8382400 (7.99 GiB 8.58 GB)
  Used Dev Size : 8382400 (7.99 GiB 8.58 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Wed May 20 12:53:26 2015
          State : clean, degraded, recovering
 Active Devices : 1
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 1

 Rebuild Status : 13% complete

           Name : raidtest:0  (local to host raidtest)
           UUID : 72ce48ed:e3135c0d:5605621c:a94999e7
         Events : 139

    Number   Major   Minor   RaidDevice State
       2       8        1        0      spare rebuilding   /dev/sda1
       1       8       17        1      active sync   /dev/sdb1

再同期処理が走りました。
これでOKですね。

復旧手順としては

  1. 障害発生したデバイスの確認
  2. 【mdadm --detail /dev/md0】で障害発生したデバイスの状態を確認
    (取り除かれてるかどうか? 存在してfail状態か?)
  3. 必要があれば/dev/md0から障害あったHDDを削除
    mdadm /dev/md0 --fail /dev/sdd1
    mdadm /dev/md0 --remove /dev/sdd1
  4. 新しいHDDを追加
    mdadm /dev/md0 --add /dev/sda1
  5. 再同期処理を終わるまでお茶を飲みながら待つ

こんな感じですね♪
・・・ということは、サーバ構築時に

  • cat /dev/mdstat
  • mdadm --detail /dev/md0
  • pvdisplay
  • vgdisplay
  • lvdisplay

最低限、これらの情報は保管しないだめですね!

4
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?