ubuntuでソフトウェアRAID1 その2

```bash:
$ sudo apt-get install mdadm
```

RAID1構築
=============

```bash:RAID1構築
$ sudo mdadm --create /dev/md0 --auto=yes --level=raid1 --raid-devices=2 /dev/sda1 /dev/sdb1
mdadm: /dev/sda1 appears to contain an ext2fs file system
    size=976761560K  mtime=Thu Jan  1 09:00:00 1970
mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
mdadm: /dev/sdb1 appears to contain an ext2fs file system
    size=976761560K  mtime=Thu Jan  1 09:00:00 1970
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.
```

```bash:確認
$ sudo fdisk -l /dev/md0
Disk /dev/md0: 1000.1 GB, 1000069464064 bytes
ヘッド 2, セクタ 4, シリンダ 244157584, 合計 1953260672 セクタ
Units = セクタ数 of 1 * 512 = 512 バイト
セクタサイズ (論理 / 物理): 512 バイト / 512 バイト
I/O サイズ (最小 / 推奨): 512 バイト / 512 バイト
ディスク識別子: 0x00000000

ディスク /dev/md0 は正常なパーティションテーブルを含んでいません
```

RAID構成を確認
=============

```bash:同期を確認
$ cat /proc/mdstat 
Personalities : [raid1] 
md0 : active raid1 sdb1[1] sda1[0]
      976630336 blocks super 1.2 [2/2] [UU]
      [>....................]  resync =  0.1% (1477952/976630336) finish=164.9min speed=98530K/sec
      
unused devices: <none>
```

```bash:確認
$ sudo mdadm --detail /dev/md0
/dev/md0:
        Version : 1.2
  Creation Time : Wed Oct  2 13:18:08 2013
     Raid Level : raid1
     Array Size : 976630336 (931.39 GiB 1000.07 GB)
  Used Dev Size : 976630336 (931.39 GiB 1000.07 GB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : Wed Oct  2 13:20:59 2013
          State : active, resyncing 
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

  Resync Status : 2% complete

           Name : i3desk:0  (local to host i3desk)
           UUID : 12a85f07:bd9c514b:c6f32183:a76ccd04
         Events : 1

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

使えるようにする
===========

```bash:フォーマット
$ sudo mkfs.ext4 /dev/md0
mke2fs 1.42.8 (20-Jun-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
61046784 inodes, 244157584 blocks
12207879 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
7452 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
	102400000, 214990848

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done     
```

```bash:blkid確認
$ sudo blkid /dev/md0
/dev/md0: UUID="e9759194-c86e-49a1-9368-1f121cb6eca2" TYPE="ext4"
```

```bash:/etc/fstabに追記
UUID="e9759194-c86e-49a1-9368-1f121cb6eca2" /data	  ext4    errors=remount-ro 0 1
```

```bash:マウント
$ sudo mkdir /data
$ sudo mount /data
```