mdadm RAID on Linux · uwot.eu
another meaningless subtitle

mdadm RAID on Linux

· by fabio · Read in about 2 min · (359 Words)
CentOS fedora mdadm RAID

Every time I have to setup a software RAID in Linux using mdadm I forget something, this time I am writing it down once and for all (or at least I hope so).
For the sake of simplicity I will use the creation of a RAID1 as example but this very same procedure can be applied for any other kind of RAID.

.:. RAID array creation

1. Partition the drives

This step must be repeated for each drive of the array (/dev/sdb and /dev/sdc in my case).

[root@CentOS ~]$ gdisk /dev/sdb
### create a new GUID
Command (? for help): o
### create a new partition
Command (? for help): n

2. Create the array with mdadm

[root@CentOS ~]$ mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb1 /dev/sdc1

To check the array synching status use the following command:

[root@CentOS ~]$ watch cat /proc/mdstat

If for some reason you decide to use the –assume-clean parameter when creating the RAID I strongly suggest to manually run the sync operation as soon as possible, to do so use:

[root@CentOS ~]$ echo repair > /sys/block/mdX/md/sync_action

RAID resync minimum and maximum speed can be controlled by manipulating the following two variables:

[root@CentOS ~]$ echo *** > /proc/sys/dev/raid/speed_limit_min
[root@CentOS ~]$ echo *** > /proc/sys/dev/raid/speed_limit_max

3. Create mdadm.conf file
This file is used by mdadm to reconfigure the RAID at every boot, if everything is working correctly it should be superfluous since information about the array configuration are already written in every disk’s superblock.
The default location for CentOS is /etc but be aware that other distro put it in /etc/mdadm/.

[root@CentOS ~]$ mdadm --detail --scan --verbose >> /etc/mdadm.conf
[root@CentOS ~]$ echo MAILADDR mailaddress@domain.smt

4. partition the volume
On a large volume XFS is a good choice, better than EXT4 actually.

### create an XFS partition
[root@CentOS ~]$ mkfs.xfs /dev/md0
### change partition label
[root@CentOS ~]$ xfs_admin -L new_label /dev/md0

.:. Delete and existing RAID array

### provide info on array composition
[root@CentOS ~]$ mdadm --detail /dev/md0
### stop, delete and clear disk's superblock
[root@CentOS ~]$ mdadm --stop /dev/md0
[root@CentOS ~]$ mdadm --remove /dev/md0
[root@CentOS ~]$ mdadm --zero-superblock /dev/sdb1 /dev/sdc1

.:. Assemble an already created array

[root@CentOS ~]$ mdadm --assemble --scan