ubuntu serverでソフトウェアraid1の設定

ファイルサーバとして自宅のESXiサーバ上のVMにsoftware raid1を構成したので、そのメモ

環境

  • ESXi:ver 5.0
  • OS:ubuntu server 11.0

構成

  • 1.5TBx2のHDDをmdadmを使用してraid1
  • データディスクとして利用

レシピ

1.HDDの取り付け
先ずは、vSphere Clientから2つのHDDを接続。
この時、もちろんHDDは別のデータストアから生成すること。
(そうでなけりゃraid1の意味が無い)
2.HDDのパーティション作成

root@ubuntu-server:~# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x754ddf48.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

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, default 1): 1
First sector (2048-33554431, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-33554431, default 33554431):
Using default value 33554431

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
root@ubuntu-server:~#

3.ファイルシステムの作成
ext4に設定

root@ubuntu-server:~# mke2fs -t ext4 /dev/sdb1
mke2fs 1.41.14 (22-Dec-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1048576 inodes, 4194048 blocks
209702 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
128 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

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

This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
root@ubuntu-server:~#

4.ラベルの設定
特に必須ではないが、最近のLinuxではラベルでパーティションを管理するようだ。

root@ubuntu-server:~# e2label /dev/sdb1 /data

2,3,4を2つのHDDに対して行うこと。
5.RAIDデバイスの作成
RAIDデバイスとしてmd0をraid1で生成する。

root@ubuntu-server:~# mdadm --create --auto=yes /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm: /dev/sdb1 appears to contain an ext2fs file system
size=16776192K 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/sdc1 appears to contain an ext2fs file system
size=16776192K mtime=Thu Jan 1 09:00:00 1970
Continue creating array? (y/n) y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

これでRAIDデバイスが生成されたので、この構成を保存する

# mdadm --examine --scan >> /etc/mdadm/mdadm.conf

6.RAIDデバイスの初期化(パーティションの生成+ファイルシステムの作成)

2,3,4と同様にしてファイルシステムを作成。ただし、fdオプションは設定しない。
7.RAIDデバイスのマウント設定

blkid /dev/md0p1

ここで表示されたUUIDを使用して, /etc/fstabを編集。

UUID=240170be-3115-xxxx-b943-0dc162f26cc1 /media/md0 ext4 defaults 0 0

fstabの設定を反映

# mount -a

マウントを確認する

# df