= Adding Software RAID under Linux = '''Note:''' The following instructions and examples are for taking 2 hard drives and creating 2 RAID-1 arrays. Please adjust your command accordingly. 1. Make sure that the Linux can see the disks 1. Install mdadm {{{ yum install mdadm }}} 1. Partition each disk into the required sizes. That is, if you plan to have the array create 2 arrays, you will need to partition EACH drive into two. Make sure the drive partitions are of equal size. {{{ # fdisk /dev/sda # fdisk /dev/sdb }}} 1. Change the system type (a.k.a. system id) of each partition to be 0xFD (Linux RAID auto-detect). Make sure you write the changes to the partition table {{{ # fdisk /dev/sda # fdisk /dev/sdb}}} 1. Create the arrays. {{{ # 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}}} 1. Create the filesystems. {{{ # mke2fs /dev/md0 # mke2fs /dev/md1}}} 1. Reboot the system to check that the arrays are started at boot-time. = Restoring an array after it fails = 1. Boot up the system and check the arrays are up and running (in degraded mode) {{{ # cat /proc/mdstat Personalities : [raid1] md1 : active raid1 sda3[0] 466890624 blocks [2/1] [U_] md0 : active raid1 sda1[0] 19534912 blocks [2/1] [U_] unused devices: }}} 1. Make sure the new drive is detected (sdb in this case) {{{ # fdisk -l Disk /dev/sda: 500.1 GB, 500107862016 bytes 255 heads, 32 sectors/track, 119702 cylinders Units = cylinders of 8160 * 512 = 4177920 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 4788 19535024 fd Linux raid autodetect /dev/sda2 4789 5268 1958400 82 Linux swap / Solaris /dev/sda3 5269 119702 466890720 fd Linux raid autodetect Disk /dev/sdb: 500.1 GB, 500107862016 bytes 255 heads, 32 sectors/track, 119702 cylinders Units = cylinders of 8160 * 512 = 4177920 bytes Disk /dev/sdb doesn't contain a valid partition table Disk /dev/md0: 20.0 GB, 20003749888 bytes 2 heads, 4 sectors/track, 4883728 cylinders Units = cylinders of 8 * 512 = 4096 bytes Disk /dev/md0 doesn't contain a valid partition table Disk /dev/md1: 478.0 GB, 478095998976 bytes 2 heads, 4 sectors/track, 116722656 cylinders Units = cylinders of 8 * 512 = 4096 bytes Disk /dev/md1 doesn't contain a valid partition table}}} 1. Copy the partition table to the new drive (we will copy sda to sdb in this example) {{{ # dd if=/dev/sda of=/dev/sdb bs=1024 count=1 # partprobe /dev/sdb}}} 1. Re-add all partitions for the new drive {{{ # mdadm --add /dev/md0 /dev/sdb1 # mdadm --add /dev/md1 /dev/sdb3}}} 1. Make sure that the drive re-syncs: {{{ # cat /proc/mdstat}}}