Mdadm

From David's Wiki
\( \newcommand{\P}[]{\unicode{xB6}} \newcommand{\AA}[]{\unicode{x212B}} \newcommand{\empty}[]{\emptyset} \newcommand{\O}[]{\emptyset} \newcommand{\Alpha}[]{Α} \newcommand{\Beta}[]{Β} \newcommand{\Epsilon}[]{Ε} \newcommand{\Iota}[]{Ι} \newcommand{\Kappa}[]{Κ} \newcommand{\Rho}[]{Ρ} \newcommand{\Tau}[]{Τ} \newcommand{\Zeta}[]{Ζ} \newcommand{\Mu}[]{\unicode{x039C}} \newcommand{\Chi}[]{Χ} \newcommand{\Eta}[]{\unicode{x0397}} \newcommand{\Nu}[]{\unicode{x039D}} \newcommand{\Omicron}[]{\unicode{x039F}} \DeclareMathOperator{\sgn}{sgn} \def\oiint{\mathop{\vcenter{\mathchoice{\huge\unicode{x222F}\,}{\unicode{x222F}}{\unicode{x222F}}{\unicode{x222F}}}\,}\nolimits} \def\oiiint{\mathop{\vcenter{\mathchoice{\huge\unicode{x2230}\,}{\unicode{x2230}}{\unicode{x2230}}{\unicode{x2230}}}\,}\nolimits} \)

Mdadm is used to create linux MD raids.

Usage

# Check the status of /dev/md0
mdadm -D /dev/md0

Create a raid array

See https://www.digitalocean.com/community/tutorials/how-to-create-raid-arrays-with-mdadm-on-ubuntu#creating-a-raid-1-array

First use gdisk to create a linux raid partition (FD00) on all your disks. Note that is purely convention and is optional.

Then run the following to create /dev/md0.

# Raid 1 example with 2 disks
mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1

# Raid 6 example with 4 disks
mdadm --create /dev/md0 --level=6 --raid-devices=4 /dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1

# Now you have a block device /dev/md0 on which you can add LUKS, LVM, or a filesystem.

# Check sync progress
cat /proc/mdstat

Add hot spare

See https://tuxfixer.com/how-to-add-hot-spare-volume-to-the-existing-mdadm-software-raid-array/

mdadm --add /dev/md0 $DEVICE

Scrubs

On Ubuntu, md will automatically scrub on the first Sunday of every month using a systemd timer.
During a scrub, you can check the status with

cat /proc/mdstat

You can check for bad blocks using

cat /sys/block/md0/md/mismatch_cnt

Changing Raid Levels

Note: I haven't tested this.
This procedure is primarilly for expanding when you get a new disk.

Raid 1 to Raid 5

https://unix.stackexchange.com/questions/610100/is-it-possible-to-keep-data-in-procedure-raid1-growing-to-raid5

Raid 5 to Raid 6

See Also

  1. LUKS