# Setup software RAID-5 in CentOS

```bash
mdadm -E /dev/sd[b-k]
#Partitioning the Disks for RAID
mdadm -E /dev/sd[b-k]1 # If no super-blocks detected, than we can move forward to create a new RAID 5 setup on these drives.
############
umount /data[1-5]
for DEV in `ls /dev/sd[b-f]`
parted /dev/sdb print
parted /dev/sdb mktable gpt
parted /dev/sdb rm 1
parted /dev/sdb mkpart primary 1 100%

mdadm -C /dev/md0 -l 5 -n 4 -x 1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1

umount /data[6-9] && umount /data10
for DEV in `ls /dev/sd[g-k]`
parted /dev/sdg print
parted /dev/sdg mktable gpt
parted /dev/sdg rm 1
parted /dev/sdg mkpart primary 1 100%

mdadm -C /dev/md1 -l 5 -n 4 -x 1 /dev/sdg1 /dev/sdh1 /dev/sdi1 /dev/sdj1 /dev/sdk1

##########
# mdadm --create /dev/md0 --level=5 --raid-devices=10 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1 /dev/sdg1 /dev/sdh1 /dev/sdi1 /dev/sdj1 /dev/sdk1
# mdadm -C /dev/md0 -l 5 -n 10 /dev/sd[b-k]1
# mdadm -C /dev/md0 -l 5 -n 8  -x 2 /dev/sd[b-k]1 #add two Spare Drive.

cat /proc/mdstat
watch -n1 cat /proc/mdstat
mdadm --detail /dev/md0
mdadm -D /dev/md0
#----------------------#

mkfs.ext4 /dev/md0
mkfs.ext4 /dev/md1
mount /dev/md0 /data1 -o noatime
mount /dev/md1 /data2 -o noatime
###########
vim /etc/fstab
#/dev/md0                /data1              ext4    defaults,noatime        0 0
#/dev/md1                /data2              ext4    defaults,noatime        0 0

mount -av # check whether any errors in fstab entry.

# Step 5: Save Raid 5 Configuration
mdadm --detail --scan --verbose >> /etc/mdadm.conf

# Step 6: Adding Spare Drives
# What the use of adding a spare drive? its very useful if we have a spare drive, if any one of the disk fails in our array, this spare drive will get active and rebuild the process and sync the data from other disk, so we can see a redundancy here.
# For more instructions on how to add spare drive and check Raid 5 fault tolerance, read #Step 6 and #Step 7 in the following article.

# Add Spare Drive to Raid 5 Setup(https://www.tecmint.com/create-raid-6-in-linux/)
```

## In short

```bash
### make raid5
umount /data[1-9] && umount /data10 && for i in {b..k} ;do parted /dev/sd$i rm 1 && parted /dev/sd$i mkpart primary 1 100%;done
mdadm -C /dev/md0 -l 5 -n 4 -x 1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1 && mdadm -C /dev/md1 -l 5 -n 4 -x 1 /dev/sdg1 /dev/sdh1 /dev/sdi1 /dev/sdj1 /dev/sdk1 && watch -n1 cat /proc/mdstat
### mkfs
mkfs.ext4 -T largefile /dev/md0 && mkfs.ext4 -T largefile /dev/md1 &
### save config
mdadm --detail --scan --verbose >> /etc/mdadm.conf
### mount
mount /dev/md0 /data1 -o noatime && mount /dev/md1 /data2 -o noatime
### update fstab
sed -i '/data/d' /etc/fstab
cat >> /etc/fstab << EOF
/dev/md0                /data1              ext4    defaults,noatime        0 0
/dev/md1                /data2              ext4    defaults,noatime        0 0
EOF
```

## Raid10

```bash
umount /data[1-2]
mdadm -S /dev/md0
mdadm -S /dev/md1
for i in {b..k} ; do parted /dev/sd$i mktable gpt && parted /dev/sd$i mkpart primary 1 100%; done
mdadm --zero-superblock /dev/sd[b-k]1
mdadm -C /dev/md0 -l 10 -n 10 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1 /dev/sdg1 /dev/sdh1 /dev/sdi1 /dev/sdj1 /dev/sdk1
```

## Reference

1. [Creating RAID 5 (Striping with Distributed Parity) in Linux – Part 4](https://www.tecmint.com/create-raid-5-in-linux/)
2. [使用parted对大于2TB的硬盘分区](http://blog.51cto.com/jackeyge/1878676)
3. [Linux 创建和管理软RAID实例](https://www.jianshu.com/p/f207c58642b0)
4. [RAID详解，Linux系统下使用mdadm程序实现常用软件RAID的各种配置](https://www.dwhd.org/20150522_103540.html)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.junyangz.com/ops/setup-software-raid-5-in-centos.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
