Create a RAID array for a Linux instance

更新时间:
复制 MD 格式

Combine multiple disks into a RAID array for higher capacity, read/write bandwidth, reliability, and availability.

Prerequisites

Multiple data disks of the same size and category are created and attached to an ECS instance. See Create a data disk and Attach a data disk.

Usage notes

RAID levels

Common RAID levels and their trade-offs:

Level

Advantage

Disadvantage

Scenario

RAID 0 (Striping)

Data striping with parallel read/write for higher performance.

Note

Disk striping divides data into fixed-size blocks (stripes) and distributes them across multiple disks.

No redundancy. If one disk fails, all data is lost.

High-performance scenarios without redundancy needs, such as temporary storage and caching.

RAID 1 (Mirroring)

Mirrors all data across disks. If one disk fails, data remains available.

Requires at least twice the disk capacity for mirroring.

Applications requiring high data protection, such as databases and file servers.

RAID 10

Combines RAID 1 mirroring and RAID 0 striping for both redundancy and high read/write performance.

Requires twice the disk capacity and at least four disks.

Applications requiring both high performance and redundancy.

Select a RAID level based on your data protection, performance, capacity, and cost requirements.

The following figure illustrates how each RAID level stores data blocks A through F.

Note

Disk bandwidth is subject to instance-level limits. For disk bandwidth limits of each instance type, see Instance family.

RAID stripe size

The optimal stripe size depends on your workload and application. Test different stripe sizes to determine the best fit.

Recommended stripe sizes by workload type:

  • General-purpose workloads: 64 KB or 128 KB. These sizes provide balanced read/write performance.

  • Sequential read workloads (such as large file transfers and video editing): 256 KB or 512 KB.

  • Random read workloads (such as database applications): 32 KB.

Important

An excessively small stripe size can cause the following issues:

  • Disk file fragmentation, which wastes disk space.

  • IOPS limits may be reached before throughput limits. Larger stripe sizes yield higher throughput for sequential reads.

Disk snapshot limits

Ensure snapshot consistency when backing up RAID array disks. Restoring from unsynchronized snapshots can compromise array integrity.

Use snapshot-consistent groups to restore data from multiple disks to the same point in time.

Procedure

This section uses the mdadm command on Linux to create a RAID array named /dev/md0 for data disks on an ECS instance running Ubuntu 22.04.

  1. Connect to an ECS instance.

    For information about the connection methods, see Connection method overview.

  2. View all disks on the instance:

    lsblk

    Sample output:

    image.png

  3. Create the /dev/md0 RAID array with the mdadm command.

    Select a RAID level based on your business requirements.

    Note

    If mdadm is not installed, run sudo apt-get install mdadm to install it.

    RAID 0 level

    sudo mdadm --create /dev/md0 --level=0 --raid-devices=5 --chunk=512 /dev/vd[bcdef]
    • --level=0: the RAID 0 level.

    • --raid-devices=5: the RAID array consists of five disks.

    • --chunk=512: the stripe size is 512 KB. Adjust based on your workload.

    • /dev/vd[bcdef]: the five disks /dev/vdb, /dev/vdc, /dev/vdd, /dev/vde, and /dev/vdf.

    Sample output:

    image.png

    RAID 1 level

    sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/vd[bc]
    • --level=1: the RAID 1 level.

    • --raid-devices=2: the RAID array consists of two disks.

    • /dev/vd[bc]: the two disks /dev/vdb and /dev/vdc.

    RAID 10 level

    sudo mdadm --create /dev/md0 --level=10 --raid-devices=4 --chunk=512 /dev/vd[bcde]
    • --level=10: the RAID 10 level.

    • --raid-devices=4: the RAID array consists of four disks.

    • --chunk=512: the stripe size is 512 KB. Adjust based on your workload.

    • /dev/vd[bcde]: the four disks /dev/vdb, /dev/vdc, /dev/vdd, and /dev/vde.

  4. View the /dev/md0 RAID array details:

    sudo mdadm --detail /dev/md0

    Sample output:

    image.png

  5. Create a file system on the RAID array. This example creates an ext4 file system.

    Replace ext4 with your preferred file system type.

    sudo mkfs.ext4 /dev/md0

    Sample output:

    image.png

  6. Save the RAID configuration and enable automatic reassembly on boot:

    sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
  7. Mount the file system.

    1. (Optional) Create a mount point. This example creates /media/raid0.

      sudo mkdir /media/raid0
      Note

      You can also mount the file system on an existing directory, such as /mnt.

    2. Mount the file system. This example mounts /dev/md0 on /media/raid0.

      To customize data security and performance trade-offs, specify mount parameters. See Mount Ext4 file systems with options.

      • (Recommended) For balanced data security and performance, mount without specifying parameters:

        sudo mount /dev/md0 /media/raid0
      • For high data security with lower performance:

        sudo mount -o rw,atime,sync,barrier,data=journal /dev/md0 /media/raid0
      • For high performance with lower data security:

        sudo mount -o defaults,noatime,nodiratime,nobarrier,nodelalloc,data=writeback /dev/md0 /media/raid0
    3. View the RAID array mount information:

      df -h

      If the file system appears at the specified mount point, the mount succeeded.

      image.png

  8. Configure automatic mount on boot.

    Add an entry for the RAID array to /etc/fstab.

    1. Add the mount entry to /etc/fstab:

      sudo sh -c "echo `blkid /dev/md0 | awk '{print $2}' | sed 's/\"//g'` /media/raid0 ext4 defaults 0 0 >> /etc/fstab"
      • /dev/md0: the RAID array name.

      • /media/raid0: the mount point. Replace with your actual mount point if different.

      • ext4: the file system type. Replace with the actual type.

      • defaults: the mount parameters. See Mount Ext4 file systems with options for details.

      Note

      To allow the instance to boot without the RAID array mounted, add the nofail mount option. The nofail option allows the instance to boot even if a disk mount error occurs. On Ubuntu, also add the nobootwait option.

    2. Verify the mount entry:

      cat /etc/fstab

      If the entry was added to the /etc/fstab file, /media/raid0 appears in the output.

      image.png

    3. Mount all file systems in /etc/fstab. If no errors occur, the RAID array will auto-mount on the next boot.

      sudo mount -a
    4. Verify the file system is mounted:

      df -Th

      If the file system appears in the output, the mount succeeded.

      image.png