Canada  united states of america usa  linkedinfacebook   Call Us Today: 866.646.6461

Add a software RAID to Linux

linux-icon-19 We have added this tutorial, because we use it very often ourselves. (ALT is an IT consulting company, providing support for Apple, Windows and Linux based systems and servers.) It describes steps for adding extra disks to an already existing system, not converting current ones to RAID (the disks will be wiped, so don't do it on the OS partition!) We are adding a RAID1 software RAID to most common Linux distributions (the setps should work on any one of them).

We have used 2 disks for this:
/dev/sdb: 500.1
/dev/sdc 500.1

If you have disks that are part of an array (inactive or destroyed), before running any operations you will most likely have to stop that array (even though it is not used). To do so, run this command (where the md127 is the defunct array -- careful not to mix up with live arrays):

mdadm --stop /dev/md127

First disk

fdisk /dev/sdb
Command (m for help): <-- n
Command action
   e   extended
   p   primary partition <-- p
Partition number (1-4): <-- 1
First sector (2048-468862127, default 2048): <--
Last sector, +sectors or +size{K,M,G,T,P} (2048-468862127, default 468862127): <--
Command (m for help): <-- t
Hex code (type L to list codes): <-- fd

Save all:

Command (m for help): <-- w

Run this command only if the disks were previously used in a software RAID configuration

mdadm --zero-superblock /dev/sdb1

Let's see which ones we already have:

cat /proc/mdstat
md1 : active raid1 sda5[0] sdg5[1]
      441378816 blocks super 1.2 [2/2] [UU]
      bitmap: 2/4 pages [8KB], 65536KB chunk
md0 : active raid1 sda1[0] sdg1[1]
      46840832 blocks super 1.2 [2/2] [UU]

We already have md0 and md1, so let's call our new disk md2:

mdadm --create /dev/md2 --level=1 --raid-disks=2 missing /dev/sdb1

Format it as ext4

mkfs.ext4 /dev/md2

Generate new config:

cp /etc/mdadm/mdadm.conf /etc/mdadm/mdadm.conf_orig
mdadm --examine --scan >> /etc/mdadm/mdadm.conf

Second Disk

fdisk /dev/sdc

Command (m for help): <-- n
Command action
   e   extended
   p   primary partition <-- p
Partition number (1-4): <-- 1
First sector (2048-468862127, default 2048): <--
Last sector, +sectors or +size{K,M,G,T,P} (2048-468862127, default 468862127): <--
Command (m for help): <-- t
Hex code (type L to list codes): <-- fd

Save all:

Command (m for help): <-- w

Then add the disk to the array

mdadm --add /dev/md2 /dev/sdc1

For the sake of an example, here's a command to create a RAID5 array (3 disks minimum):

mdadm --create /dev/md2 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1

 Contact us for any of your IT support related issues.

Last updated Sep 21, 2019