This topic describes how to use the mdadm command of the Linux operating system to create a 200-GiB Independent Array of Independent Disks (RAID) array for multiple data disks. In this topic, an Elastic Compute Service (ECS) instance that runs the Ubuntu operating system is used.

Prerequisites

Multiple disks are created and attached to the ECS instance. We recommend that you create disks of the same capacity and category. For more information about how to create and attach a disk, see Create a disk and Attach a data disk.

Background information

RAID combines multiple disks into a disk array group. Compared with a single disk, a RAID array offers improved capacity, read/write bandwidth, reliability, and availability.

We recommend that you use the RAID 0 or RAID 1 mode and partition disks in the same size to maximize the use of disk space. We recommend that you do not use the RAID 5 or RAID 6 mode, because parity data in RAID 5 or RAID 6 mode consumes the IOPS of disks and deteriorates performance.

The following table describes the advantages, disadvantages, and application scenarios of the RAID 0 and RAID 1 modes.
Mode Advantage Disadvantage Scenario
RAID 0 Uses the striping technique to allocate I/O loads to different disks. You can increase the throughput by extending disks. The capacity and bandwidth in the array are the sum of the capacity and bandwidth of different disks. A damaged disk may cause loss of all data due to lack of data redundancy. Has high requirements for I/O performance and is applicable when data is backed up in other methods or no data backup is required.
RAID 1 Provides higher data redundancy because data is stored in different disks as images. The minimum capacity and bandwidth values of disks are the capacity and bandwidth values of the RAID array. The write performance is poor because data must be written to multiple disks at the same time. Focuses more on fault tolerance than I/O performance in key applications.

Procedure

  1. Remotely connect to an ECS instance as a root user. For more information, see Overview.
  2. Run the following command to view the information of all disk on the instance:
    lsblk
    A command output similar to the following one is returned. lsblk
  3. Run the mdadm command to create a RAID array named /dev/md0.
    You can create an array in RAID 0 or RAID 1 mode based on your actual needs.
    Note
    • In the following commands, /dev/vd[bcdef] indicates that the RAID array consists of five disks: /dev/vdb, /dev/vdc, /dev/vdd, /dev/vde, and /dev/vdf. If you want to use other disks, replace them with your disk names.
    • If you are prompted that the mdadm tool is not installed, run the apt-get install mdadm command to install the mdadm tool.
    • Run the following command to create an array in RAID 0 mode:
      mdadm --create /dev/md0 --level=0 --raid-devices=5 /dev/vd[bcdef]
      • --level=0 indicates the array in RAID 0 mode that is used for data striping.
      • --raid-devices=5 indicates that the RAID array consists of five disks.
      • /dev/vd[bcdef] indicates the five disks: /dev/vdb, /dev/vdc, /dev/vdd, /dev/vde, and /dev/vdf.
      A command output similar to the following one is returned. mdadm_raid0
    • Run the following command to create an array in RAID 1 mode:
      mdadm --create /dev/md0 --level=1 --raid-devices=5 /dev/vd[bcdef]
      • --level=1 indicates the array in RAID 1 mode that is used for data mirroring.
      • --raid-devices=5 indicates that the RAID array consists of five disks.
      • /dev/vd[bcdef] indicates the five disks: /dev/vdb, /dev/vdc, /dev/vdd, /dev/vde, and /dev/vdf.
  4. Run the following command to view the information of the /dev/md0 RAID array:
    mdadm --detail /dev/md0
    A command output similar to the following one is returned. raid0
  5. Run the following command to create a file system on the RAID array. In this example, an ext4 file system is created.

    You can also create a file system of other types.

    mkfs.ext4 /dev/md0
    A command output similar to the following one is returned. mkfs
  6. Run the following command to create a configuration file that contains the information of the RAID array and configure the RAID array to be automatically reassembled when the ECS instance starts:
    sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
  7. Mount the file system.
    1. Run the following command to create a mount point. For example, create a mount point named /media/raid0.
      mkdir /media/raid0
      Note You can attach a disk to an existing directory such as /mnt.
    2. Run the following command to mount the file system. For example, you can mount the /dev/md0 file system to the /media/raid0 mount point.
      mount /dev/md0 /media/raid0
  8. Run the following command to view the mount information of the RAID array:
    df -h
    The command output indicates that the /dev/md0 file system is mounted to the /media/rad0 mount point. Mount information

What to do next

To configure the RAID array to be automatically loaded each time the ECS instance starts, perform the following operations on the /etc/fstab configuration file.

  1. Run the following command to add the default startup setting to the /etc/fstab configuration file:
    echo `blkid /dev/md0 | awk '{print $2}' | sed 's/\"//g'` /media/raid0 ext4 defaults 0 0 >> /etc/fstab
    • /dev/md0 indicates the name of the disk array.
    • /media/raid0 indicates the mount point. If you want to mount the RAID array to a different mount point, you must replace it with the corresponding mount point.
    Note To start the ECS instance when the RAID array is not mounted, you must add the nofail setting. Even if an error occurs when you install a disk, the nofail setting allows the ECS instance to be started. If your instance runs an Ubuntu operating system, you must also add the nobootwait setting.
  2. Run the following command to mount all file systems in the /etc/fstab configuration file:
    mount -a