Operations 8 min read

Step-by-Step Guide to Building a Software RAID 5 on Linux with mdadm

Learn how to create, configure, and manage a software RAID 5 array on CentOS 7 using mdadm, covering partition preparation, RAID creation, filesystem formatting, mounting, status checks, hot‑spare handling, device removal, and expansion, with complete command examples and expected outputs.

Raymond Ops
Raymond Ops
Raymond Ops
Step-by-Step Guide to Building a Software RAID 5 on Linux with mdadm

Software RAID 5 Implementation

RAID 5 provides a balance of performance, data safety, and cost by combining striping with parity. This guide shows how to set up a RAID 5 array on CentOS 7 using

mdadm

.

1. Prepare Partitions

Use two partitions on

/dev/sda8

and

/dev/sda9

together with the whole disks

/dev/sdb

and

/dev/sdc

. Remember to change the partition type ID to

fd

(Linux RAID autodetect).

2. Create RAID 5

<code>mdadm -C /dev/md5 -a yes -l 5 -n 3 -x 1 /dev/sda8 /dev/sda9 /dev/sdb /dev/sdc</code>

Output:

<code>mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.</code>

3. Create Filesystem

<code># mkfs.ext4 /dev/md5</code>

4. Mount the Array

<code># mkdir /mnt/raid5
# mount /dev/md5 /mnt/raid5</code>

5. Generate mdadm Configuration

<code># cat /etc/mdadm.conf
ARRAY /dev/md5 metadata=1.2 spares=1 name=centos7.3.local:5 UUID=5ec4115c:ab1e25c8:ff36d8a2:74f6fd8a</code>

6. Check RAID Status

<code># cat /proc/mdstat</code>
<code>Personalities : [raid0] [raid6] [raid5] [raid4]
md5 : active raid5 sdb[4] sdc[3](S) sda9[1] sda8[0]
2095104 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/3] [UUU]</code>

7. Disable and Enable the Array

<code># umount /mnt/raid5
# mdadm -S /dev/md5   # stop
# mdadm -A /dev/md5   # start</code>

8. Simulate Disk Failure

<code># mdadm /dev/md5 -f /dev/sdc</code>

9. Remove a Failed Disk

<code># mdadm /dev/md5 -r /dev/sdc</code>

10. Re‑add a Disk

<code># mdadm /dev/md5 -a /dev/sdc</code>

11. Expand the Array (Add a Fourth Device)

<code># mdadm -G /dev/md5 -n 4 -a /dev/sdd</code>

12. Verify Filesystem Integrity and Resize

<code># e2fsck -f /dev/md5
# resize2fs /dev/md5</code>

13. Final RAID Information

<code># mdadm -D /dev/md5</code>

The final array contains four active devices and one spare, with a total size of about 3 GiB.

RAID diagram
RAID diagram
LinuxstorageSystem AdministrationCentOSRAID5mdadm
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

login 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.