Setup software RAID-5 in CentOS
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
### 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
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
Last updated