Sunday, 15. February 2009, 10:44:17
Some of you asked me a very specific questions concerning linux, some administrative tasks etc. In order not to repeat myself, I've decided to write several posts in the topic.
Today the raid arrays.
The most common raid setup is a mirror array - 2 partitions connected into singular RAID-1 volume.
How to do this?
well.. first of all you need to activate RAID modules in kernel. I think that the easiest way to do this is to hard-compile raid-1 support directly into the kernel. Of course you can also use raid1 modules, but then you'll have to take care of proper module initialization at the level of initrd and kernel startup.
The minimal setup would be:
Multi-device support (RAID and LVM) --->
[*] Multiple devices driver support (RAID and LVM)
<*> RAID support
< > Linear (append) mode (NEW)
<*> RAID-0 (striping) mode
<*> RAID-1 (mirroring) mode
< > RAID-10 (mirrored striping) mode (EXPERIMENTAL) (NEW)
< > RAID-4/RAID-5 mode (NEW)
< > RAID-6 mode (NEW)
< > Multipath I/O support (NEW)
< > Faulty test module for MD (NEW)
<*> Device mapper support
After successful compile and kernel installation (and reboot) we can now create our first raid partition. Assuming, we have two similar disks /dev/sda and /dev/sdb with similar partitions /dev/sda2 and /dev/sdb2 (not root partitions, but for instance a reiserfs filesystem mounted at /home):
In debian:
apt-get install mdadm
mdadm --create /dev/md0 --level 1 --raid-devices=2 missing /dev/sdb2
mkreiserfs --format 3.6 /dev/md0
mount /dev/md0 /mnt
cp -dpRx /home/* /mnt/
mdadm --detail --scan >> /etc/mdadm/mdadm.conf
edit and modify /etc/fstab to mount /dev/md0 at /home
reboot
After successful reboot we can add the /dev/sda2 partition into previosly created array and replicate it:
mdadm --add /dev/md0 /dev/sda2
Then issue cat /proc/mdstat - you will get something like this:
md0 : active raid1 sda2[0] sdb2[1]
9767424 blocks [2/1] [_U]
[==========>..........] recovery = 47.9%
finish=2.4min speed=x
After several minutes you'll get:
Personalities : [raid1]
md0 : active raid1 sda2[0] sdb2[1]
9767424 blocks [2/2] [UU]
This means, the array is ready.
If you want to boot from raid array (/ or /boot), then you'll need to recreate initrd filesystem (using mkinitramfs) and then modify bootloader setup:
just add root and md flags to the configuration file. For instance in grub:
kernel /vmlinuz-2.6.27.10 root=/dev/md1 md=1 ro
initrd /initrd.img-2.6.27.10-md
It's also a good idea to copy the root filesystem in 'telinit 1' and then cp -a /dev /mnt/

That's all for now

.
Of course as usually - you're on your own, I will not be held responsible for any damage - back up your data first!