How to Build a Software RAID1 on CentOS 7 Using mdadm – Step‑by‑Step Guide
This tutorial explains why and how to set up a software RAID1 on a CentOS 7 virtual machine using mdadm, covering prerequisites, disk partitioning, RAID creation, configuration, formatting, mounting, and common maintenance commands.
RAID (Redundant Arrays of Independent Disks) provides high availability and redundancy, but hardware RAID cards can be costly for large deployments; software RAID offers a cheaper alternative.
Implementation Steps
The experiment uses a CentOS 7.2 VM with two 50 GB data disks (host1). In production, RAID disks should 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 disks and set type to RAID
Use fdisk for disks ≤2 TB (type code fd) or parted for larger disks, creating a GPT label and setting the partition flag to RAID.
3. Create RAID1 with mdadm
Run:
mdadm -C /dev/md0 -ayes -l1 -n2 /dev/xvdb1 /dev/xvdc1
The note indicates software RAID cannot be used as a boot device.
Command options:
-C --create: create array
-a --auto: auto‑create device (use -a yes)
-l --level: array level (e.g., raid1)
-n --raid-devices: number of active disks
/dev/md0: array device name
Check status with:
cat /proc/mdstat
Initial resync may show ~95 % complete; a second check confirms full synchronization.
Alternatively, view details with:
mdadm -D /dev/md0
4. Create mdadm configuration file
echo DEVICE /dev/sd{a,b}1 >> /etc/mdadm.conf mdadm -Evs >> /etc/mdadm.conf
mdadm reads this file at startup to assemble arrays automatically.
5. Use the RAID device
Format and mount:
mkfs.ext4 /dev/md0
Optionally specify stride for performance, e.g.:
mkfs.ext4 -E stride=16 -b 4096 /dev/md0
6. Additional commands
Manage array health:
Mark a failed disk: mdadm /dev/md1 -f /dev/sdb5 Remove a failed disk: mdadm /dev/md1 -r /dev/sdb5 Add a new disk: mdadm /dev/md1 -a /dev/sdb7 Stop the array:
mdadm -S /dev/md1Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
