preload
Jan 22

So sometimes linux can’t automaticly start array from array members. So lets do it manually.

Get the info from array member (disk partition)


[root@sirius ~]# mdadm --examine /dev/hda1
/dev/hda1:
Magic : a92b4efc
Version : 00.90.01
UUID : b2d657f5:b881d26d:e249f8e9:a64f1406
Creation Time : Sat Jan 14 17:00:14 2006
Raid Level : raid1
Device Size : 1003904 (980.54 MiB 1028.00 MB)
Array Size : 1003904 (980.54 MiB 1028.00 MB)
Raid Devices : 2
Total Devices : 2
Preferred Minor : 0

Update Time : Thu Jan 18 18:07:52 2007
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Checksum : 26a507ac - correct
Events : 0.224

Number Major Minor RaidDevice State
this 0 3 1 0 active sync /dev/hda1

0 0 3 1 0 active sync /dev/hda1
1 1 3 65 1 active sync /dev/hdb1

As you can see that we can get lots of information from disk, but we are only intrested on UUID which identyfies the array member:


[root@sirius ~]# for i in a b; do mdadm --examine /dev/hd"$i"1 | grep -i uuid; done
UUID : b2d657f5:b881d26d:e249f8e9:a64f1406
UUID : b2d657f5:b881d26d:e249f8e9:a64f1406

So partitions hda1 and hdb1 seems to have same UUID which means that they are from same array.

And now lets start the array from those members:


[root@sirius ~]# mdadm --examine /dev/hda1 | grep UUID | awk '{ print $3 }' > /tmp/hda1
[root@sirius ~]# mdadm -A --uuid=`cat /tmp/hda1` /dev/md0

Touché.

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