Setting up a software RAID array

From Alpine Linux
Revision as of 11:59, 17 September 2007 by WikiSysop (talk | contribs) (imported from old wiki)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This document will show how to create hard disk mirroring using cheap IDE disks.

This document was written for alpine-1.3.8 or later. It is tested with alpine-1.7.3.

I will setup 2 raid devices, md0 for swap and md1 for data. I use swap on a raid1 for maximum reliability. If you prefer maximum speed, you don't need configure any raid devices for swap. Just add 2 swap partitions on different disks and linux will stripe them automatically. The downside is that at the moment one disk fails, the system will go down. Thats why I choose to put the swap on raid1.

Loading needed modules

Start with loading the ide-disk and raid1 kernel modules. If you use SATA or SCSI disks you will not need the ide-disk module.

modprobe ide-disk
modprobe raid1

Add them to /etc/modules so they get loaded during next reboot.

echo ide-disk >> /etc/modules
echo raid1 >> /etc/modules

Creating the partitions

I will use /dev/hde and /dev/hdg in this document but you will probably use /dev/hda and /dev/hdc. Note that the disks should not be connected on the same IDE bus (sharing the same IDE cable). To find what disks you have available, look in /proc/partitions or look at the /dev/disk* links that the mdev system has created.

~ $ ls -l /dev/disk*
lrwxrwxrwx    1 root     root            3 Aug 24 12:49 /dev/disk -> hde
lrwxrwxrwx    1 root     root            3 Aug 24 12:49 /dev/disk0 -> hde
lrwxrwxrwx    1 root     root            3 Aug 24 12:49 /dev/disk1 -> hdg


Create the partitions using fdisk.

fdisk /dev/hde

I will use 512MB for swap and the rest for /var. My partition table looks like this:

   Device Boot      Start         End      Blocks   Id  System
/dev/hde1               1         992      499936+  fd  Linux raid autodetect
/dev/hde2             993       77545    38582712   fd  Linux raid autodetect


Remeber to set the type (with 't' in fdisk) to Linux raid autodetect. (fd)

Do the same with your second disk.

fdisk /dev/hdg

Mine looks like this:

   Device Boot      Start         End      Blocks   Id  System
/dev/hdg1               1         992      499936+  fd  Linux raid autodetect
/dev/hdg2             993       77545    38582712   fd  Linux raid autodetect

== Setting up the raid array Install mdadm to set up the arrays.

apk_add mdadm

Make the /dev nodes before creating the arrays. NcopaNOTE:Ncopa This is not necessary with alpine-1.7.3

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

Create the arrays.

mdadm --create -l 1 -n 2 /dev/md0 /dev/hde1 /dev/hdg1
mdadm --create -l 1 -n 2 /dev/md1 /dev/hde2 /dev/hdg2

Monitorin sync status

You should now be able to see the array syncronize by looking at the contents of /proc/mdstat.

~ $ cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 hdg2[1] hde2[0]
      38582592 blocks [2/2] [UU]
      [==>..................]  resync = 10.5% (4056192/38582592) finish=68.5min speed=8388K/sec

md0 : active raid1 hdg1[1] hde1[0]
      499840 blocks [2/2] [UU]

unused devices: <none>

You don't need to wait til it is fully syncronized to continue.

Saving config

Create the /etc/mdadm.conf file so mdadm knows how your raid setup is:

mdadm --detail --scan > /etc/mdadm.conf

To make sure the raid devices start during the next reboot run:

rc_add -s 10 -k mdadm-raid

The ~~-s 10~~ option is to make sure that the raid arrays are started early, before things like lvm and localmount.

Use lbu commit as usual to save configs to usb or floppy.

You should now be able to create swap on /dev/md0 and a filesystem on /dev/md1 using the ~~mkswap~~ and ~~mkfs.*~~ commands.