Linux Software RAID

mdadm is a tool that allows for creation and management of software RAID arrays on Linux. Creating an array is a rather straightforward process.

Install packages

The only package needed is mdadm itself

apt install mdadm

Partition disks

We'll need to parition the disks to be used in the array before creating it. This isn't anything complicated, we will just be creating a single partition using all the space on each disk.

Use lsblk to get a list of disks attached to your system.

lsblk command

Then use fdisk to edit the partition table of the first disk. In my case this would be /dev/sdb. Be sure that you are selecting the correct disk as selecting the wrong one can result in data being lost.

fdisk /dev/sdb

Use g to create a new GUID partition table. Use n to create a new partition, and then just press enter at all of the prompts to accept the defaults. Finally use w to write the changes. You can use lsblk again to verify the change and you should see that /dev/sdb now has a partition /dev/sdb1.

fdisk command

Repeat this process for your other disks before continuing.

Create the array

Creating the array is done with a single command, but takes just a bit of planning.

mdadm --create /dev/md0 --level=5 --raid-devices=3 /dev/sdb1 /dev/sdc1 /dev/sdd1 --spare-devices=1 /dev/sde1

After creating the array run the following command to get details and the status of the array. It will take a bit to initialize the array, you will know this is done when the state is clean. You do not need to wait for the array to completely intialize to continue.

mdadm --detail /dev/md0

Take note of the UUID and name values as we will need them in the next step.

Before moving on we need to make a filesystem on the array. I'm going to make a simple EXT4 filesystem here.

mkfs.ext4 /dev/md0

Configuration Files

Open the mdadm configuration file at /etc/mdadm/mdadm.conf and append this line. Replace uuid and name with the values you got when running mdadm --detail, replace 0 whatever ID you chose.

ARRAY /dev/md0 metadata=1.2 UUID=uuid name=name

Optionally, create an /etc/fstab entry for automounting of the array. Replace /mnt/raid with the directory where you want to mount the array. If you made a filesystem other than ext4 make sure to change that value.

/dev/md0 /mnt/raid ext4 defaults 0 1


Consider donating if this article was useful. [BTC]