「mdadm」によるRAID5の構築

「mdadm」を利用してソフトウェアRAIDを構築する。
RAIDのレベルは5にするので、kernelの
CONFIG_MD
CONFIG_BLK_DEV_MD
CONFIG_MD_RAID5
を有効にする必要がある。
なお、ここではhde,hdf,hdg,hdhで構築するものとする。

パーティションの作成

「mdadm」で自動的にパーティションが作成されるが、自分で作成することにする。
基本的にタイプの指定をfdにする以外は通常通り。
なお、1台分のみ記述しているが、必要分行う。

Linux# fdisk /dev/hde <= fdiskの実行
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.


The number of cylinders for this disk is set to 38913.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n <= パーティションの新規作成
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-38913, default 1): <= 空Enter
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-38913, default 38913): <= 空Enter
Using default value 38913

Command (m for help): t <= タイプの変更
Selected partition 1
Hex code (type L to list codes): fd <= Linux raid用にする
Changed system type of partition 1 to fd (Linux raid autodetect)

Command (m for help): p <= 設定の確認

Disk /dev/hde: 320.0 GB, 320072933376 bytes
255 heads, 63 sectors/track, 38913 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/hde1               1       38913   312568641   fd  Linux raid autodetect

Command (m for help): w <= 変更を保存
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
RAIDの構築

RAIDの構築

作成したパーティション上にRAIDを構築する。
なお、この作業はディスク容量や性能にもよるが、非常に時間が掛かるので注意。

Linux# mdadm -C /dev/md0 -l5 -n4 -f /dev/hd[efgh]1

構築状態の確認

2通りの方法で確認できる。

Linux# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] [multipath] [faulty]
md0 : active raid5 hdh1[3] hdg1[2] hdf1[1] hde1[0]
      937705728 blocks level 5, 64k chunk, algorithm 2 [4/4] [UUUU]
      [==>..................]  resync = 10.8% (33933500/312568576) finish=212.2min speed=21879K/sec

unused devices: <none>

矢印が進行状況で、終了すれば表示が消える。

もう一つの確認方法は以下のように行う。

Linux# mdadm -D /dev/md0
/dev/md0:
        Version : 00.90.03
  Creation Time : Sat Jun  9 19:58:02 2007
     Raid Level : raid5
     Array Size : 937705728 (894.27 GiB 960.21 GB)
  Used Dev Size : 312568576 (298.09 GiB 320.07 GB)
   Raid Devices : 4
  Total Devices : 4
Preferred Minor : 0
    Persistence : Superblock is persistent

    Update Time : Sat Jun  9 19:58:56 2007
          State : active, resyncing
 Active Devices : 4
Working Devices : 4
 Failed Devices : 0
  Spare Devices : 0

         Layout : left-symmetric
     Chunk Size : 64K

 Rebuild Status : 10% complete

           UUID : 66ad02b5:4990e226:a37c74f2:26514327
         Events : 0.3

    Number   Major   Minor   RaidDevice State
       0      33        1        0      active sync   /dev/hde1
       1      33       65        1      active sync   /dev/hdf1
       2      34        1        2      active sync   /dev/hdg1
       3      34       65        3      active sync   /dev/hdh1

Rebuild Status が現在の進行状況である。

RAIDのマウント

ファイルシステムの構築

ext3でフォーマットする。

Linux# mkfs -t ext3 /dev/md0

デバイスのマウント

Linux# mkdir /mnt/data <= マウント用のディレクトリを作成
Linux# mount /dev/md0 /mnt/data <= マウント

自動マウント

Linux起動時に自動的にマウントするようにする。

Linux# echo 'DEVICE /dev/hd[efgh]1' > /etc/mdadm.conf
Linux# mdadm -Ds >> /etc/mdadm.conf


Linux# vi /etc/fstab <= 設定ファイルの編集
/dev/md0   /mnt/data   ext3   defaults    0 2 <= 追加

異常時のメール通知

RAID異常時にメールを送るようにする。

Linux# vi /etc/mdadm.conf <= 設定ファイルの編集
MAILADDR kaz@red-snow.net <= 追加(宛先の指定)
リビルド

hdf1が壊れたものと仮定して、リビルドを行う。
なお、このリビルド作業は上記のRAIDの構築と同じだけの時間がかかるので注意。

Linux# mdadm /dev/md0 -f /dev/hdf1 <= hdf1を不良とする
mdadm: set /dev/hdf1 faulty in /dev/md0

Linux# cat /proc/mdstat <= RAIDの状態の確認
Personalities : [raid6] [raid5] [raid4] [multipath] [faulty]
md0 : active raid5 hdh1[3] hdg1[2] hdf1[1](F) hde1[0] <= hdf1に(F)が表示される
      937705728 blocks level 5, 64k chunk, algorithm 2 [4/3] [UU_U] <=hdf1の位置が _ になっている

unused devices: <none>

Linux# mdadm /dev/md0 -r /dev/hdf1 <= hdf1を切り離す
mdadm: hot removed /dev/hdf1

Linux# mdadm /dev/md0 -a /dev/hdf1 <= hdf1を追加(リビルド)
mdadm: hot added /dev/hdf1

Linux# cat /proc/mdstat <= RAIDの状態の確認
Personalities : [raid6] [raid5] [raid4] [multipath] [faulty]
md0 : active raid5 hdh1[3] hdg1[2] hdf1[1] hde1[0]
      937705728 blocks level 5, 64k chunk, algorithm 2 [4/4] [UUUU]

unused devices: <none>
RAIDの解除

マウントしている場合はアンマウントしてから解除する。

Linux# umount /mnt/data <= アンマウント
Linux# mdadm -S /dev/md0 <= RAIDの解除

後は、各ディスクのフォーマットや設定ファイルの変更等を適宜行う。

▲ページのトップへ