preload
Dec 27

So lets create array. I’ll use mdadm on this example. I assume that we will have two SATA drives and they have been allready partitioned. Make the partition types Linux raid autodetect which is fd in fdisk. Also remember to make bootable flags with option a.

We will do two raid-devices, swap and root.

mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
mdadm --create /dev/md1 --level=1 --raid-devices=2 /dev/sda2 /dev/sdb2

If you get error that device md0 or 1 doesnt exist just create them.

mknod /dev/md0 b 9 0
mknod /dev/md1 b 9 1

You can also make array with single disk to degraded mode if you are doing system rescue or adding raid to a existing system.

mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 missing

Now you have array running. Make filesystem to it and mount it for use.

 
mkfs.ext3 /dev/md1 
mount /dev/md1 /to/some/mountpoint

And you are done.

Thanks for Dan who made correction to syntax for creating array. There should be dashes in raid-devices directive. I corrected the instruction.

Dec 27

Most common tools for handling linux software RAID would be mdadm and raidtools.

Check raidstatus:

# cat /proc/mdstat 
Personalities : [linear] [raid0] [raid1] [raid5] [multipath] [raid6] [raid10] [faulty] 
md1 : active raid1 hdb2[1] hda2[0]
      38073984 blocks [2/2] [UU]
      
md0 : active raid1 hdb1[1] hda1[0]
      1003904 blocks [2/2] [UU]

I am too lazy to show what it will show when broken, you will know when you see it. Also check dmesg for errors.

So after reboot if you have identical disk you can just copy partition table:

sfdisk -d /dev/hda | sed s/hda/hdb/ > /tmp/hdb
sfdisk -f /dev/hdb < /tmp/hdb

I think that everyone can figure out what just happened. No add the fresh disk to degraded array:

raidtools

raidhotadd /dev/md0 /dev/hdb1
raidhotadd /dev/md1 /dev/hdb2

mdadm

mdadm /dev/md0 -a /dev/hdb1
mdadm /dev/md1 -a /dev/hdb2

After that if the reconstruction speed is low, you can speed it up by raising the speed_limit_min under /proc/sys/dev/raid

 echo 10000 > /proc/sys/dev/raid/speed_limit_min
Dec 26

Here will be those everyday commands and stuff what you just cant remember when needed 😉 These examples are ment to be my personal notes. Use them at your own risk, you have been warned.

Most of the examples are for linux.