Operations 7 min read

How to Build a Software RAID1 on CentOS 7 with mdadm: Step‑by‑Step Guide

Learn how to set up a software RAID1 on a CentOS 7 VM using mdadm, covering environment preparation, partitioning, RAID creation, configuration file generation, filesystem formatting, mounting, and essential management commands, while highlighting performance considerations and common pitfalls.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
How to Build a Software RAID1 on CentOS 7 with mdadm: Step‑by‑Step Guide

1. Application Scenario

RAID (Redundant Arrays of Independent Disks) provides high availability and redundancy. Hardware RAID cards are reliable but expensive for large deployments; software RAID offers a cost‑effective alternative.

2. Implementation Steps

Software RAID relies on the OS and consumes CPU resources. In Linux it is implemented with mdadm.

Experimental Environment

CentOS 7.2 VM named host1 with two 50 GB data disks.

Note: In production both disks in a RAID must be identical in brand, model, and capacity.

1. Verify mdadm installation

rpm -qa | grep mdadm

Output shows mdadm‑3.3.2‑7.el7.x86_64.

2. Partition the two data disks and set partition type to RAID

Use fdisk for disks under 2 TB; for larger disks use parted. In fdisk the RAID partition type code is fd. With parted first create a GPT label, then create partitions and set the raid flag.

3. Create RAID1 with mdadm

Note: Software RAID cannot be used as a boot device.

mdadm -C /dev/md0 -a yes -l1 -n2 /dev/xvdb1 /dev/xvdc1

Command options:

-C --create: create array

-a --auto: accept creation (use -a yes to create in one step)

-l --level: array level (e.g., linear, raid0, raid1, …)

-n --raid-devices: number of active disks

/dev/md0: name of the array

4. Verify array status

Run cat /proc/mdstat to see resync progress. Example screenshots show 95.7 % completed on first check and full sync on second.

Alternatively, mdadm -D /dev/md0 displays detailed array information.

5. Create mdadm configuration file

echo DEVICE /dev/sd{a,b}1 >> /etc/mdadm.conf mdadm -Evs >> /etc/mdadm.conf

The mdadm daemon reads /etc/mdadm.conf and assembles arrays automatically.

6. Use the new RAID device

mkfs.ext4 /dev/md0

When formatting, the -E stride=16 option can improve performance by matching the stripe size to the filesystem block size.

mkfs.ext4 -E stride=16 -b 4096 /dev/md0

7. Additional management commands

To handle failed disks:

Add: mdadm /dev/md1 -a /dev/sdb7 Remove: mdadm /dev/md1 -r /dev/sdb5 Mark as failed: mdadm /dev/md1 -f /dev/sdb5 Stop array:

mdadm -S /dev/md1
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxCentOSRAIDSoftware RAIDmdadm
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.