This page looks best with JavaScript enabled

Software Raid Commands

 ·  ☕ 2 min read

mdadm is a tool which allow us to configure and manage RAID devices

Create a Soft Raid 5

First create partitions on disks then assembre then on raid those partition

To create a RAID 5 we need at least 3 disks.
Suppose to have 3 disk /dev/sda /dev/sdb /dev/sdc

Examine the disks

# -E --examine
mdadm --examine /dev/sda /dev/sdb /dev/sdc

If the output shows “no md superblock detected” it means the the disks do not contain any raid. Good! go on.

using fdisk create a primary partition on each disk ad set to fd type Linux Raid autodetect

# -E --examine
mdadm --examine /dev/sda /dev/sdb /dev/sdc

now the disks are ready to be used… (optional we will use another disk as spare)

# -l --level
# -n --raid-devices
mdadm --create --verbose /dev/md5 --level=5 \
    --raid-devices=3 /dev/sda1 /dev/sdb1 /dev/sdc1 \
    -x /dev/sde1
mkfs.ext4 –F /dev/md5

Monitor Raid

mdadm -D /dev/md5
cat /proc/mdstat

Set a disk in FAIL state

mdadm -f /dev/md5 /dev/sda1

Remove FAILED disk

mdadm -r /dev/md5 /dev/sda1

Add a new disk to RAID

mdadm -a /dev/md5 /dev/sdd1

Update RAID configuration

# -s --scan
# -D --detail
# --verbose
mdadm -D -v -s > /etc/mdadm/mdadm.conf

update-initramfs -u

Start Stop RAID

start

# if mdadmn.conf exists
mdadm -As /dev/md5
# if mdadm.conf does not exists
mdadm -A /dev/md5 /dev/sda1 /dev/sdb1 /dev/sdc1

stop

mdadm -S /dev/md5

Tips to play and test

no need to create partitions

losetup -D

start and loop for all the disks

fallocate -m 200M disc0 # create a file of 200Mb size
losetup -f disc0 # create /dev/loop0

then play….