• Home
    Step by step guides
    Creating a raid with NVME on EC2 instance

    Creating a Software RAID 0 with two NVME HDD on an EC2 Instance can improve your disk I/O performance. RAID 0 also known as striping, writes data across multiple drives, which can increase both read and write speed. However, remember that RAID 0 does not provide redundancy. If one drive fails, all data is lost.

    Here are the steps to set it up:

    1. For this task, you’ll need the mdadm tool which is a Linux utility used to manage and monitor software RAID devices. Ensure it is installed on your system:
    sudo yum install mdadm -y   #for Amazon Linux
    sudo apt-get install mdadm   #for Ubuntu
    1. Since we’re using NVMe drives, check if NVME command line utilities (nvme-cli) are present. If not, install with the following commands:
    sudo yum install nvme-cli -y   #for Amazon Linux
    sudo apt-get install nvme-cli   #for Ubuntu
    1. Identify NVMe devices. You can list all NVMe devices installed on your Amazon EC2 instance by using the nvme list command as follows:
    sudo nvme list

    You would see a list of NVMe devices with their respective namespaces such as /dev/nvme0n1, /dev/nvme1n1 etc.

    1. Before creating the RAID array, make sure that no partitions exist on the NVMe devices:
    sudo wipefs -a /dev/nvme0n1
    sudo wipefs -a /dev/nvme1n1
    1. Now you can create the RAID 0 array using the mdadm --create command. The simplest usage is as below:
    sudo mdadm --create --verbose /dev/md0 --level=0 --raid-devices=2 /dev/nvme0n1 /dev/nvme1n1

    In this command, /dev/md0 is the name of new RAID array, --level=0 specifies the RAID level, --raid-devices=2 specifies the number of RAID devices and /dev/nvme0n1 /dev/nvme1n1 are the NVMe devices that you identified earlier.

    1. You can verify the creation of RAID array by:
    cat /proc/mdstat

    If the RAID array is created successfully, it will show the details of the RAID array /dev/md0.

    1. Now, you need to create a filesystem on this RAID array before you can use it. If you want to create an ext4 filesystem, use the mkfs.ext4 command:
    sudo mkfs.ext4 /dev/md0
    1. Create a directory where you’d like to mount this filesystem:
    sudo mkdir /mnt/raid
    1. Now, mount this filesystem to the directory you just created:
    sudo mount /dev/md0 /mnt/raid
    1. To ensure the RAID array is remounted automatically after a reboot, it’s good practice to edit the /etc/fstab file:
    echo '/dev/md0 /mnt/raid ext4 defaults,nofail 0 0' | sudo tee -a /etc/fstab
    1. Run df -h to ensure that your RAID array is up and correctly mounted.