Operations 8 min read

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

This tutorial walks through creating a software RAID 5 array on a CentOS 7 system using mdadm, covering partition preparation, array creation, filesystem formatting, mounting, configuration, monitoring, fault simulation, disk removal, re‑adding disks, and expanding the array to add a fourth member.

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

Software RAID 5 Implementation

RAID 5 is a storage solution that balances performance, data safety, and cost. It combines the striping of RAID 0 with parity like RAID 1, offering read speeds similar to RAID 0, higher space utilization than RAID 1, and moderate write overhead.

1. Partition

Use two partitions on /dev/sda (e.g., /dev/sda8 and /dev/sda9) together with two whole disks /dev/sdb and /dev/sdc. Remember to set 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

Options: -l specifies the RAID level (5). -a yes automatically creates the device node. -c sets the chunk size. -x defines the number of spare disks.

3. Create filesystem # mkfs.ext4 /dev/md5 4. Mount

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

5. Generate configuration file

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

Check RAID status:

# cat /proc/mdstat
Personalities : [raid0] [raid6] [raid5] [raid4]
md5 : active raid5 sdb[4] sdc[3](S) sda9[1] sda8[0]

Detailed info: # mdadm -D /dev/md5 Shows three active devices and one spare.

6. Disable and enable

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

Verify that the array restarts correctly.

7. Simulate /dev/sdc failure # mdadm /dev/md5 -f /dev/sdc 8. Remove /dev/sdc # mdadm /dev/md5 -r /dev/sdc The disk is hot‑removed from the array.

9. Add a disk back to the RAID # mdadm /dev/md5 -a /dev/sdc The disk appears as a spare again.

10. Expand the array from 3 to 4 members # mdadm -G /dev/md5 -n 4 -a /dev/sdd Run a filesystem check and resize:

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

Final status shows four active devices and one spare.

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.

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