haase.dev/ blog

Software Raid Mdadm

August 22, 2020

Use partitions instead of raw devices and make sure the partitions are a bit smaller than the actual device. This makes it easier to replace the device with a new one of another manufacturer.

mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1
mdadm --detail --scan | tee -a /etc/mdadm/mdadm.conf

To show the status of your raid:

cat /proc/mdstat

Encryption

cryptsetup -v luksFormat /dev/md0

Keyfile

dd bs=512 count=4 if=/dev/urandom of=/root/keyfile iflag=fullblock
chmod 600 /root/keyfile

cryptsetup luksAddKey /dev/md0 /root/keyfile
cryptsetup open /dev/md0 md0_crypt --key-file /root/keyfile

blkid /dev/md0

/etc/crypttab
md0_crypt UUID=2a5375bf-2162-413c-a6a8-fbeb47659c85 /root/keyfile luks