Pages

Monday, 16 January 2017

Setting up software RAID in Linux with mdadm

Although software RAID has seen a sizeable decrease in use with the now frequent use of virtualisation and the underlying storage RAID'ed on a SAN - there are still some use cases for setting up software RAID.

This article will discuss each step from start to finish on how to setup software RAID on Linux with the help of mdadm.

We should firstly note that software RAID with mdadm is handled by the md kernel driver (not a module).

A driver file will be created automatically for the RAID array when using mdadm (/dev/mdX) - but we can manually create one if desired using the mknod command - with the appropriate driver major number - 9 in this case:

cat /proc/devices | grep md

mknod /dev/mdc b 9 0

Before using the disks for RAID - we must firstly create a new partition and ensure that auto-raid detection will pick up the disk - this can be performed with fdisk by making sure the partition type is set to 'fd':

fdisk /dev/sdc
n # new partition
p # primary partition
<accept defaults>
t # change disk type
fd # set disk type to 'Linux rapid auto'
w # write changes

and repeat for the other disk.

We can now create the RAID set (using RAID 1 for this example):

mdadm -C /dev/md0 -l raid1 -n 2 /dev/sdb1 /dev/sdc1

mdadm: Note: this array has metadata at the start and
    may not be suitable as a boot device.  If you plan to
    store '/boot' on this device please ensure that
    your boot-loader understands md/v1.x metadata, or use
    --metadata=0.90
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

Create a new file-system for it with:

mkfs.btrfs /dev/md0

Generate the mdadm configuration for persistence:

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

Ensure that the new partitions are mounted at boot in the fstab:

vi /etc/fstab

And ensure that the RAID set is initialised on boot by adding the following:

echo "mdadm --assemble -s" >> /etc/rc.d/rc.local

We can verify the configuration of the RAID set with:

mdadm --detail /dev/md0

and also check replication status with:

cat /proc/mdstat



No comments:

Post a Comment