Software Raid mdadm on EC2 instance with EBS volumes
If you want to use EBS volumes on EC2 instance as a software raid, there is very nice way to do that.
You need to perform few steps, for example creating Raid1 and preserving it's creation after server reboot:
# yum install mdadm
Now, first check your devices, for this example we will presume their names are /dev/xvdf and /dev/xvdg (modify this to suit your needs):
# mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/xvdf /dev/xvdg
Next, we want to find out if everything went OK:
# cat /proc/mdstat
You should see something like:
Personalities : [raid1]
md0 : active raid1 xvdg[2] xvdf[0]
5241844 blocks super 1.2 [2/2] [UU]
unused devices:
Another way to grab mdadm details (following command should give you mdadm device name, which is in our case /dev/md0):
# mdadm --detail --scan
Now you can ask for more details about that mdadm device (/dev/md0):
# mdadm --detail /dev/md0
Now if you want to preserve mdadm on next reboot, do this:
# mv /etc/mdadm.conf /etc/mdadmconf.-backup
# mdadm --detail --scan > /etc/mdadm.conf
After this step, you have ready mdadm system and device, but without any filesystem actually installed. Now you can create a filesystem on mdadm device:
# mkfs.ext4 /dev/md0
After that, you can put your mdadm device in /etc/fstab, for example:
/dev/md0 /mnt/raid1 ext4 defaults 0 0
And mount it:
# mount /mnt/raid1
That's it!