If you’re looking for a balance of speed, reliability, and storage capacity for your Linux system, RAID 10 might be the perfect solution for you. RAID 10 combines the best of RAID 1 (mirroring) and RAID 0 (striping) to give you a fault-tolerant and high-performance storage solution. In this tutorial, we’ll guide you through creating a RAID 10 array in Linux using the mdadm tool.
Prerequisites
Before we begin, you’ll need:
- A Linux system (we’ll be using Ubuntu in this tutorial, but the process is similar for other distributions)
- Four or more storage devices (hard drives or SSDs) of the same size
Step 1: Install mdadm
First, you’ll need to install the mdadm tool. On Ubuntu, you can do this by running:
sudo apt-get update
sudo apt-get install mdadm
For other Linux distributions, consult their respective package managers (e.g., yum
for Fedora or zypper
for openSUSE).
Step 2: Prepare the Storage Devices
To create a RAID 10 array, you’ll need to partition your storage devices. For this tutorial, we assume that you have four storage devices with device names /dev/sdb, /dev/sdc, /dev/sdd, and /dev/sde. Replace these names with the appropriate device names on your system.
Use the fdisk
utility to create partitions on each device:
sudo fdisk /dev/sdb
In the fdisk
utility, follow these steps:
- Press
n
to create a new partition. - Press
p
for a primary partition. - Press
1
to create the first partition on the device. - Press
Enter
twice to accept the default start and end sector values. - Press
t
to change the partition type. - Enter
fd
to set the partition type to Linux RAID autodetect. - Press
w
to write the changes and exit.
Repeat this process for the remaining devices: /dev/sdc, /dev/sdd, and /dev/sde.
Step 3: Create the RAID 10 Array
Now that the storage devices are prepared, it’s time to create the RAID 10 array using the mdadm
command:
sudo mdadm --create --verbose /dev/md0 --level=10 --raid-devices=4 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1
This command creates a RAID 10 array named /dev/md0
using the four partitions we created in the previous step. Adjust the number of --raid-devices
and device names as needed for your configuration.
Step 4: Save the RAID Configuration
After creating the RAID 10 array, you’ll want to save its configuration to ensure it’s recognized at system startup:
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
This command appends the RAID configuration to the mdadm.conf
file.
Next, update your system’s initial RAM disk to include the RAID configuration:
sudo update-initramfs -u
Step 5: Create a Filesystem on the RAID Array
Now it’s time to create a filesystem on the RAID array. In this example, we’ll create an ext4 filesystem:
sudo mkfs.ext4 /dev/md0
You can choose a different filesystem type depending on your requirements (e.g., XFS or Btrfs).
Step 6: Mount the RAID Array
Create a mount point for the RAID array:
sudo mkdir /mnt/raid10
Mount the RAID array to the newly created mount point:
sudo mount /dev/md0 /mnt/raid10
To ensure the RAID array is mounted automatically at startup, add an entry to the /etc/fstab
file:
echo '/dev/md0 /mnt/raid10 ext4 defaults 0 0' | sudo tee -a /etc/fstab
Replace ext4
with the filesystem type you chose in Step 5.
Final Thoughts
Congratulations! You’ve successfully created a RAID 10 array in Linux using the mdadm
tool. RAID 10 provides a combination of speed and redundancy, making it an excellent choice for many use cases. Be sure to explore other RAID configurations How to Create RAID 5 in Ubuntu and How to Create RAID 1 in Ubuntu