Setting up a software RAID array

From Alpine Linux
Revision as of 15:44, 20 February 2008 by Nangel (talk | contribs) (Reverted edits by 141.223.149.36 (Talk); changed back to last version by 213.234.126.131)

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.7.

I will setup 1 raid device for use as physical storage for lvm .

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 Oct 17 13:23 /dev/disk -> hda
lrwxrwxrwx    1 root     root            3 Oct 17 13:23 /dev/disk0 -> hda
lrwxrwxrwx    1 root     root            3 Oct 17 13:23 /dev/disk1 -> hdc

Create the partitions using fdisk.

fdisk /dev/hda

I will create one single partition of type Linux raid autodetect. Use n in fdisk to create the partition and t to set type. Logical volumes will be created later. My partition table looks like this ('p' to print partition table):

   Device Boot      Start         End      Blocks  Id System
/dev/hda1               1       17753     8388261  fd Linux raid autodetect

Use w to write and quit. Do the same with your second disk.

fdisk /dev/hdc

Mine looks like this:

   Device Boot      Start         End      Blocks  Id System
/dev/hdc1               1       17753     8388261  fd Linux raid autodetect

Setting up the raid array

Install mdadm to set up the arrays.

apk_add mdadm

If you use an alpine version earlier than 1.7.3 you need to make the /dev nodes before creating the arrays.

mknod /dev/md0 b 9 0

Create the array.

mdadm --create --level=1 --raid-devices=2 /dev/md0 /dev/hda1 /dev/hdc1

Monitoring 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] 
md0 : active raid1 hdc1[1] hda1[0]
      8388160 blocks [2/2] [UU]
      [=========>...........]  resync = 45.3% (3800064/8388160) finish=0.3min  speed=200003K/sec

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.

The raid device /dev/md0 is now ready to be used with lvm or mkfs.