Setting up a software RAID array: Difference between revisions

From Alpine Linux
(tested with 1.7.7. fixed italic formatting)
No edit summary
Line 3: Line 3:
This document was written for alpine-1.3.8 or later. It is tested with alpine-1.7.7.
This document was written for alpine-1.3.8 or later. It is tested with alpine-1.7.7.


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.
I will setup 1 raid device for use as physical storage for [[Setting up Logical Volumes with LVM | lvm]] .


== Loading needed modules ==
== Loading needed modules ==
Line 18: Line 18:
== Creating the partitions ==
== 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.
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*
  ls -l /dev/disk*
  lrwxrwxrwx    1 root    root            3 Aug 24 12:49 /dev/disk -> hde
  lrwxrwxrwx    1 root    root            3 Oct 17 13:23 /dev/disk -> hda
  lrwxrwxrwx    1 root    root            3 Aug 24 12:49 /dev/disk0 -> hde
  lrwxrwxrwx    1 root    root            3 Oct 17 13:23 /dev/disk0 -> hda
  lrwxrwxrwx    1 root    root            3 Aug 24 12:49 /dev/disk1 -> hdg
  lrwxrwxrwx    1 root    root            3 Oct 17 13:23 /dev/disk1 -> hdc
 


Create the partitions using fdisk.
Create the partitions using fdisk.


  fdisk /dev/hde
  fdisk /dev/hda


I will use 512MB for swap and the rest for /var. My partition table looks like this:
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/hde1              1        992      499936+  fd  Linux raid autodetect
/dev/hde2            993      77545    38582712  fd  Linux raid autodetect


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


Remeber to set the type (with 't' in fdisk) to Linux raid autodetect. (fd)
Use '''w''' to '''w'''rite and quit.
 
Do the same with your second disk.
Do the same with your second disk.


Line 41: Line 38:


Mine looks like this:
Mine looks like this:
 
     Device Boot      Start        End      Blocks Id System
     Device Boot      Start        End      Blocks   Id System
  /dev/hdc1               1       17753    8388261 fd Linux raid autodetect
  /dev/hdg1               1         992      499936+  fd  Linux raid autodetect
  /dev/hdg2            993      77545    38582712  fd Linux raid autodetect


== Setting up the raid array
== Setting up the raid array

Revision as of 11:52, 17 October 2007

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/hdg

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