Linux RAID with mdadm Cheat SheetLinux RAID with mdadm Cheat Sheet

RAID Levels

RAID 0Stri­pes data evenly across two or more disks.
RAID 1Mirr­ors data on two or more disks.
RAID 2Rarely used, Bit-level striping with Hamming code for error correc­tion.
RAID 3Rarely used, byte-level striping with a dedicated parity.
RAID 4Block-­level striping with dedi­cated parity.
RAID 5Block-­level striping with dist­ributed parity.
RAID 6Block-­level striping with double distri­buted parity.

Nested RAID Levels

NumberDesc­rip­tionEfficiency
RAID 01Block-­level striping, and mirroring without parity1/stripes
RAID 10Mirroring without parity, and block-­level stripingstripes/n
RAID 50Block-­level striping with distri­buted parity, and block-­level striping(1-str­ipes)/n
RAID 60Block-­level striping with double distri­buted parity, and block-­level striping(1-2*s­tri­pes)/n

Formatting Disks for Use with mdadm

DISC­LAIMER: PROCEED WITH CAUTION.
MAKE SURE YOU KNOW WHAT DISK YOU ARE OPERATING ON. IT IS VERY EASY TO DO IRREVO­CABLE DAMAGE TO YOUR SYSTEM IF YOU DON’T.
0. Figure out disk location in the file system:
lsblk -o name,s­ize­,fs­typ­e,t­ype­,mo­unt­point
1. Formatting with fdisk
sudo fdisk /dev/sdx
2. Navigatng fdisk: just press the following keys when promted to create new linux RAID type primary partition
n, p, 1, Enter, Enter, t, fd, w
3. Repeat steps 1 and 2 for each disk that will be included in new array
sudo fdisk /dev/sdy
n, p, 1, Enter, Enter, t, fd, w

Creating RAID arrays

Create a mirrored array
mdadm –create /dev/md0 –level=1 /dev/sdx1 /dev/sdy1

Assembling RAID arrays

Assemble an existing array
mdadm --assemble /dev/md0 /dev/sdx1 /dev/sdy1
mdadm --scan --assemble --uuid=<UUID>

Resetting Existing RAID Devices

Find the active arrays
cat /proc/­mdstat
Unmount the array
sudo umount /dev/md0
Stop and remove the array
mdadm --stop /dev/md0
mdadm --remove /dev/md0
Find the devices used to build the array
lsblk -o name,f­sty­pe,­mou­ntp­oint
Zero out the respective superb­locks
sudo mdadm --zero­-su­per­block /dev/sdx
sudo mdadm --zero­-su­per­block /dev/sdy
Remove persistent references to the array
sudo nano /etc/f­stab
Comment out or remove the reference to the array.
# /dev/md0 /mnt/md0 ext4 defaults,nofail,discard 0 0
In /etc/­mda­dm/­mda­dm.c­onf comment out or remove the array reference
sudo nano /etc/m­dad­m/m­dad­m.conf
Comment out the reference
# ARRAY /dev/md0 metada­ta=1.2 name=m­dad­mwr­ite:0 UUID=xxxx