12
13

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.

【CentOS7.1】mdadmでRAID構築した際のHDD交換手順

Last updated at Posted at 2016-04-12

はじめに

こちらの記事の後日談となります。

結局その後どうなったのか

  • sync_actionでチェックしてる途中で完全にHDDが認識しなくなる
  • 忙しくてHDD買いに行く暇もなく(めんどくさい)放置
  • 他のディスクが壊れると厄介なのでやっとのことで重い腰を上げる・・・

前提

  • CentOS7
  • HDD500GB × 4本 RAID10 の構成
  • 交換したHDDは/dev/sdbに割り当てされている

やったこと

  • fdiskコマンドで新HDDにパーティションを作成
  • mdadmコマンドで新HDDをRAIDへ組み込む

手順詳細

新HDDでパーティション作成

他のディスクのパーティション情報を確認

[root@localhost ~]# fdisk -l /dev/sda

Disk /dev/sda: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
Disk label type: dos
ディスク識別子: 0x000e56b2

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sda1            2048   945397759   472697856   fd  Linux raid autodetect
/dev/sda2       945397760   972118015    13360128   fd  Linux raid autodetect
/dev/sda3   *   972118016   972632063      257024   fd  Linux raid autodetect
/dev/sda4       972632064   976773119     2070528    5  Extended
/dev/sda5       972634112   976773119     2069504   fd  Linux raid autodetect

パーティション作成

[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.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
Building a new DOS disklabel with disk identifier 0x248708bf.

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

コマンド (m でヘルプ): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
パーティション番号 (1-4, default 1): 1
最初 sector (2048-976773167, 初期値 2048): 2048
Last sector, +sectors or +size{K,M,G} (2048-976773167, 初期値 976773167): 945397759
Partition 1 of type Linux and of size 450.8 GiB is set

コマンド (m でヘルプ): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
パーティション番号 (2-4, default 2): 2
最初 sector (945397760-976773167, 初期値 945397760): 945397760
Last sector, +sectors or +size{K,M,G} (945397760-976773167, 初期値 976773167): 972118015
Partition 2 of type Linux and of size 12.8 GiB is set

コマンド (m でヘルプ): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
パーティション番号 (3,4, default 3): 3
最初 sector (972118016-976773167, 初期値 972118016): 972118016
Last sector, +sectors or +size{K,M,G} (972118016-976773167, 初期値 976773167): 972632063
Partition 3 of type Linux and of size 251 MiB is set

コマンド (m でヘルプ): n
Partition type:
   p   primary (3 primary, 0 extended, 1 free)
   e   extended
Select (default e): e
Selected partition 4
最初 sector (972632064-976773167, 初期値 972632064): 972632064
Last sector, +sectors or +size{K,M,G} (972632064-976773167, 初期値 976773167): 976773119
Partition 4 of type Extended and of size 2 GiB is set

コマンド (m でヘルプ): n
All primary partitions are in use
Adding logical partition 5
最初 sector (972634112-976773119, 初期値 972634112): 972634112
Last sector, +sectors or +size{K,M,G} (972634112-976773119, 初期値 976773119): 976773119
Partition 5 of type Linux and of size 2 GiB is set

コマンド (m でヘルプ): t
パーティション番号 (1-5, default 5): 1
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'

コマンド (m でヘルプ): t
パーティション番号 (1-5, default 5): 2
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'

コマンド (m でヘルプ): t
パーティション番号 (1-5, default 5): 3
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'

コマンド (m でヘルプ): t
パーティション番号 (1-5, default 5): 5
Hex code (type L to list all codes): fd
Changed type of partition 'Linux' to 'Linux raid autodetect'

コマンド (m でヘルプ): a
パーティション番号 (1-5, default 5): 3

コマンド (m でヘルプ): p

Disk /dev/sdb: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
Disk label type: dos
ディスク識別子: 0x248708bf

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sdb1            2048   945397759   472697856   fd  Linux raid autodetect
/dev/sdb2       945397760   972118015    13360128   fd  Linux raid autodetect
/dev/sdb3   *   972118016   972632063      257024   fd  Linux raid autodetect
/dev/sdb4       972632064   976773119     2070528    5  Extended
/dev/sdb5       972634112   976773119     2069504   fd  Linux raid autodetect

コマンド (m でヘルプ): w
パーティションテーブルは変更されました!

ioctl() を呼び出してパーティションテーブルを再読込みします。
ディスクを同期しています。

確認

[root@localhost ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 500.1 GB, 500107862016 bytes, 976773168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O サイズ (最小 / 推奨): 4096 バイト / 4096 バイト
Disk label type: dos
ディスク識別子: 0x248708bf

デバイス ブート      始点        終点     ブロック   Id  システム
/dev/sdb1            2048   945397759   472697856   fd  Linux raid autodetect
/dev/sdb2       945397760   972118015    13360128   fd  Linux raid autodetect
/dev/sdb3   *   972118016   972632063      257024   fd  Linux raid autodetect
/dev/sdb4       972632064   976773119     2070528    5  Extended
/dev/sdb5       972634112   976773119     2069504   fd  Linux raid autodetect

新HDDをRAIDへ組み込む

RAIDの状態を確認

[root@localhost ~]# cat /proc/mdstat
Personalities : [raid10]
md124 : active raid10 sda1[0] sdd1[3] sdc1[2]
      945133568 blocks super 1.2 512K chunks 2 near-copies [4/3] [U_UU]
      bitmap: 2/8 pages [8KB], 65536KB chunk

md125 : active raid10 sdc2[2] sdd2[3] sda2[0]
      26703872 blocks super 1.2 512K chunks 2 near-copies [4/3] [U_UU]
      bitmap: 1/1 pages [4KB], 65536KB chunk

md126 : active raid10 sdc3[2] sdd3[3] sda3[0]
      513024 blocks super 1.0 512K chunks 2 near-copies [4/3] [U_UU]
      bitmap: 1/1 pages [4KB], 65536KB chunk

md127 : active raid10 sdd5[3] sdc5[2] sda5[0]
      4136960 blocks super 1.2 512K chunks 2 near-copies [4/3] [U_UU]

unused devices: <none>

/dev/sdb1/dev/md124へ組み込む

[root@localhost ~]# mdadm -a /dev/md124 /dev/sdb1
mdadm: added /dev/sdb1

確認

[root@localhost ~]# cat /proc/mdstat
Personalities : [raid10]
md124 : active raid10 sdb1[4] sda1[0] sdd1[3] sdc1[2]
      945133568 blocks super 1.2 512K chunks 2 near-copies [4/3] [U_UU]
      [>....................]  recovery =  0.3% (1615808/472566784) finish=140.8min speed=55717K/sec
      bitmap: 2/8 pages [8KB], 65536KB chunk

md125 : active raid10 sdc2[2] sdd2[3] sda2[0]
      26703872 blocks super 1.2 512K chunks 2 near-copies [4/3] [U_UU]
      bitmap: 1/1 pages [4KB], 65536KB chunk

md126 : active raid10 sdc3[2] sdd3[3] sda3[0]
      513024 blocks super 1.0 512K chunks 2 near-copies [4/3] [U_UU]
      bitmap: 1/1 pages [4KB], 65536KB chunk

md127 : active raid10 sdd5[3] sdc5[2] sda5[0]
      4136960 blocks super 1.2 512K chunks 2 near-copies [4/3] [U_UU]

unused devices: <none>

他のパーティションも追加

[root@localhost ~]# mdadm -a /dev/md125 /dev/sdb2
mdadm: added /dev/sdb2
[root@localhost ~]# mdadm -a /dev/md126 /dev/sdb3
mdadm: added /dev/sdb3
[root@localhost ~]# mdadm -a /dev/md127 /dev/sdb5
mdadm: added /dev/sdb5

再度確認

[root@localhost ~]# cat /proc/mdstat
Personalities : [raid10]
md124 : active raid10 sdb1[4] sda1[0] sdd1[3] sdc1[2]
      945133568 blocks super 1.2 512K chunks 2 near-copies [4/3] [U_UU]
      [>....................]  recovery =  2.8% (13591424/472566784) finish=135.8min speed=56320K/sec
      bitmap: 2/8 pages [8KB], 65536KB chunk

md125 : active raid10 sdb2[4] sdc2[2] sdd2[3] sda2[0]
      26703872 blocks super 1.2 512K chunks 2 near-copies [4/3] [U_UU]
        resync=DELAYED
      bitmap: 1/1 pages [4KB], 65536KB chunk

md126 : active raid10 sdb3[4] sdc3[2] sdd3[3] sda3[0]
      513024 blocks super 1.0 512K chunks 2 near-copies [4/3] [U_UU]
        resync=DELAYED
      bitmap: 1/1 pages [4KB], 65536KB chunk

md127 : active raid10 sdb5[4] sdd5[3] sdc5[2] sda5[0]
      4136960 blocks super 1.2 512K chunks 2 near-copies [4/3] [U_UU]
        resync=DELAYED

unused devices: <none>

リカバリ完了後のステータスを確認

  • 約三時間後
[root@localhost ~]# cat /proc/mdstat ; date
Personalities : [raid10]
md124 : active raid10 sdb1[4] sda1[0] sdd1[3] sdc1[2]
      945133568 blocks super 1.2 512K chunks 2 near-copies [4/4] [UUUU]
      bitmap: 0/8 pages [0KB], 65536KB chunk

md125 : active raid10 sdb2[4] sdc2[2] sdd2[3] sda2[0]
      26703872 blocks super 1.2 512K chunks 2 near-copies [4/4] [UUUU]
      bitmap: 0/1 pages [0KB], 65536KB chunk

md126 : active raid10 sdb3[4] sdc3[2] sdd3[3] sda3[0]
      513024 blocks super 1.0 512K chunks 2 near-copies [4/4] [UUUU]
      bitmap: 0/1 pages [0KB], 65536KB chunk

md127 : active raid10 sdb5[4] sdd5[3] sdc5[2] sda5[0]
      4136960 blocks super 1.2 512K chunks 2 near-copies [4/4] [UUUU]

unused devices: <none>

おわりに

とりあえず初自宅RAID、初自宅鯖のHDD交換が無事終わりました。
HDD障害検知の仕組みを入れたり、Docker入れたりして色々と遊べるようにしたいと思います!

参考

12
13
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
12
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?