Snippets mdadm

Setting minimum and maximum speeds for devices

1
2
3
# 70000 kilobytes/s ~ 68 Mb/s
echo "70000" > /proc/sys/dev/raid/speed_limit_min
echo "100000" > /proc/sys/dev/raid/speed_limit_max

sysctl analogue

1
2
dev.raid.speed_limit_min=70000
dev.raid.speed_limit_max=100000
1
2
3
4
5
6
7
8
9
# From one device
mdadm --create /dev/md0 --metadata=1.2 --level=1 --raid-devices=2 missing /dev/sdb1
# Launch
mdadm --assemble /dev/md9 /dev/sdf9
# Addition
mdadm --manage /dev/md1 --add /dev/sda1
# 
mdadm --detail /dev/mdX
mdadm --detail --scan

Backup array to file

This is a very convenient and easy way to back up your laptop.

1
2
3
4
5
6
7
8
9
10
11
12
dd if=/dev/zero of=/mnt/md1.raw bs=1M count=1 seek=128412
losetup /dev/loop6 /mnt/md1.raw
mdadm --manage /dev/md1 --add /dev/loop6
mdadm --grow /dev/md1 --raid-devices=3

# Waiting for the synchronization to complete
printf '3' > /proc/sys/vm/drop_caches
sync

mdadm /dev/md1 --fail /dev/loop6
mdadm /dev/md1 --remove /dev/loop6
mdadm --grow /dev/md1 --raid-devices=2

Backup array to external drive

This way you can have a fully working copy of the system.

1
2
3
4
5
6
7
8
9
10
11
mdadm --manage /dev/md1 --add /dev/sdx1
# Wait
printf '3' > /proc/sys/vm/drop_caches
sync
# If this is a partition with rootfs
update-grub
grub-install --recheck /dev/sdx
sync
mdadm /dev/md1 --fail /dev/sdx
mdadm /dev/md1 --remove /dev/sdx
mdadm --grow /dev/md1 --raid-devices=2

Starting a check/repair

1
2
echo 'check' > /sys/block/md0/md/sync_action
echo 'repair' > /sys/block/md0/md/sync_action