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.
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/sdcOutput:
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md5 started.3. Create Filesystem
# mkfs.ext4 /dev/md54. Mount the Array
# mkdir /mnt/raid5
# mount /dev/md5 /mnt/raid55. Generate mdadm Configuration
# cat /etc/mdadm.conf
ARRAY /dev/md5 metadata=1.2 spares=1 name=centos7.3.local:5 UUID=5ec4115c:ab1e25c8:ff36d8a2:74f6fd8a6. 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 # start8. Simulate Disk Failure
# mdadm /dev/md5 -f /dev/sdc9. Remove a Failed Disk
# mdadm /dev/md5 -r /dev/sdc10. Re‑add a Disk
# mdadm /dev/md5 -a /dev/sdc11. Expand the Array (Add a Fourth Device)
# mdadm -G /dev/md5 -n 4 -a /dev/sdd12. Verify Filesystem Integrity and Resize
# e2fsck -f /dev/md5
# resize2fs /dev/md513. Final RAID Information
# mdadm -D /dev/md5The final array contains four active devices and one spare, with a total size of about 3 GiB.
Signed-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.
Raymond Ops
Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.
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.
