Configuring RAID on AWS EC2

David Zhao
3 min readAug 31, 2020

--

If you are using an EC2 instance with attached disks (NVMe, SSD, HDD) or want to get more out of your EBS disks, you may want to use RAID. Unfortunately, there is no hardware RAID available on AWS, so you will have to deal with figuring out your own software RAID settings.

Determining RAID Levels: 0, 1, 5, 6, etc.

When choosing between RAID levels on an EC2 instance, you should consider the following factors:

  • AWS EBS volumes are by design highly reliable and less prone to failure. If you’re using ephemeral attached storage, you likely don’t care about long-term reliability anyway.
  • More complex RAID setups (RAID 5, RAID 6) will consume a lot of your provisioned IOPs just in overhead.

“Amazon EBS volume data is replicated across multiple servers in an Availability Zone to prevent the loss of data from the failure of any single component. This replication makes Amazon EBS volumes ten times more reliable than typical commodity disk drives.” — AWS EC2 Documentation

I would personally only use RAID 0 on AWS to get the most performance out of my disks.

Creating a RAID0 Array

To start configuring a RAID array, you need to figure out what disks you’ll be using.

sudo lsblk

The lsblk command will list the disks attached to your instance. If you are using an instance with NVMe drives, they will normally be /dev/nvme1n1, /dev/nvme2n1, /dev/nvme3n1/, /dev/nvme4n1 (as applicable).

Then initialize your RAID array using mdadm:

sudo mdadm --create --verbose /dev/md0 --level=0 --raid-devices=4 /dev/nvme1n1 /dev/nvme2n1 /dev/nvme3n1 /dev/nvme4n1

If you’re creating the array from brand-new disks, this should be near-instant.

Format your new raid array using mkfs. I chose to use the XFS file system according to recommendations by RedHat, but you can also choose ext4.

sudo mkfs.xfs /dev/md0

Mount the raid device by first creating a mount point and then mounting the RAID array to it.

sudo mkdir /mnt/raiddrive
sudo mount /dev/md0 /mnt/raiddrive

Be sure to add the RAID array information so that it is recreated on boot.

sudo mdadm — detail — scan | sudo tee -a /etc/mdadm.conf

Add the new configuration and array information to initramfs to make sure things stay consistent.

sudo dracut -H -f /boot/initramfs-$(uname -r).img $(uname -r)

And you can now access your new speedy array at /mnt/raiddrive!

Folder Permissions

If you find that you can’t write to the new directory, you can use the following command to give your user access.

sudo chown -R ec2-user /mnt/raiddrive

Creating a RAID1 Array

Follow the exact same commands as for creating a RAID0 array except while initializing the array using mdadm, set the raid level to 1 rather than 0.

sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=4 /dev/nvme1n1 /dev/nvme2n1 /dev/nvme3n1 /dev/nvme4n1

Conclusion

With a RAID0 array, you can potentially quadruple your IOPS with an EC2 instance with ephemeral storage. With EBS disks, a 20% or 30% increase seems more practical. If you have any questions, benchmarks, or suggestions, feel free to leave a comment!

Sign up to discover human stories that deepen your understanding of the world.

--

--

David Zhao
David Zhao

Written by David Zhao

Full-Stack Engineer at Stripe

Responses (1)

Write a response