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

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

Output:

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

3. Create Filesystem

# mkfs.ext4 /dev/md5

4. Mount the Array

# mkdir /mnt/raid5
# mount /dev/md5 /mnt/raid5

5. Generate mdadm Configuration

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

6. Check RAID Status

# cat /proc/mdstat
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]

7. Disable and Enable the Array

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

8. Simulate Disk Failure

# mdadm /dev/md5 -f /dev/sdc

9. Remove a Failed Disk

# mdadm /dev/md5 -r /dev/sdc

10. Re‑add a Disk

# mdadm /dev/md5 -a /dev/sdc

11. Expand the Array (Add a Fourth Device)

# mdadm -G /dev/md5 -n 4 -a /dev/sdd

12. Verify Filesystem Integrity and Resize

# e2fsck -f /dev/md5
# resize2fs /dev/md5

13. Final RAID Information

# mdadm -D /dev/md5

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

RAID diagram
RAID diagram
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.

LinuxstorageCentOSRAID5mdadm
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

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.