Raids using mdadm

Raids using mdadm

Translation made by DeepL Traduttore


The RAID is a disk grouping system that allows you to read and write to disks in a specific way, thus offering you greater security and speed than ungrouped hard disks.



This tutorial is going to be developed in Linux, so, in order to continue, we have to install the tool we are going to use.

sudo apt-get install mdadm


List the discs

In order to create a RAID, we must first know the disks that our computer has, so, we have the following command.

fdisk -l

Once this has been done, we can then move on to setting it up.


Configure RAIDs

RAID 0 - Striping

This RAID distributes the data between the different disks, this means a higher write and read speed, but if a disk stops working, the information is lost.


Create the Raid

To create RAID 0, let's use the following command.

mdadm --create /dev/md/raid0 --level=0 --raid-device=2 /dev/sdb /dev/sdc

Using this, we create a RAID 0 in the folder /dev/md/raid0 using the disks /dev/sdb and /dev/sdc

To see if it has been created correctly and to be able to locate it, we have two options.

cat /proc/mdstat
mdadm -D /dev/md/raid0

Using the command of the first option, we get the name of the RAID, so now we can use it to identify it and see more information.

mdadm -D /dev/md127


Create a partition

To create a partition, we must know the name of the RAID to use it next

fdisk /dev/md127

After executing this, we have to enter some specific values.

> n
> p
> w

Now we can see the changes we have made to create the partition.

fdisk -l


Format the partition

Now we are going to format the partition we have created previously, when creating the partition you will have assigned a different name to the RAID partition, so, we need to know to use it next.

mkfs -t ntfs /dev/md127p1


Mount the partition

We are going to mount the partition to be able to access it, therefore, we create the folder where we want to mount it.

mkdir /media/raid0
mount /dev/md127p1 /media/raid0


Delete the RAID

If we want to delete the RAID, first we have to stop it in order to delete it, then we delete all the information from the disks so that the grouping disappears.

mdadm --stop /dev/md127
mdadm --zero-superblock /dev/sdb /dev/sdc


RAID 1 - Mirror

This RAID duplicates the data between the different disks, this means more security, but the speed of writing and reading does not improve.


Crear el RAID

mdadm --create /dev/md/raid1 --level=1 --raid-devices=2 /dev/sdb /dev/sdd

Using this, we created a RAID 1 in the mask /dev/md/raid1 using the disks /dev/sdb and /dev/sdd

mdadm -D /dev/md/raid1


Cause a disk failure

Let's test the RAID for performance by causing a disk failure

mdadm /dev/md127 -f /dev/sdb
mdadm -D /dev/md/raid1


Add a disc

We are now going to add a disk to the RAID to be restored from the failure we caused

mdadm /dev/md127 --add /dev/sdf
mdadm -D /dev/md/raid1


Raid 5 - Striping and Parity

This RAID distributes the data between the different disks adding parity, this means a higher read and write speed, and allows up to 1 disk to fail.


Create the RAID

mdadm --create /dev/md/raid5 --level=5 --raid-devices=3 /dev/sdb /dev/sdd /dev/sde

Using this, we create a RAID 5 in the folder /dev/md/raid5 using the disks /dev/sdb, /dev/sdd and /dev/sde

mdadm -D /dev/md/raid5


RAID 5 from 3 RAID 0

We created the three RAIDs 0

mdadm --create /dev/md/raid1 --level=0 --raid-devices=2 /dev/sdb /dev/sdc
mdadm --create /dev/md/raid2 --level=0 --raid-devices=2 /dev/sdd /dev/sde
mdadm --create /dev/md/raid3 --level=0 --raid-devices=2 /dev/sdf /dev/sdg

Later we create the RAID 5 using the 3 Raids 0 previously created.

mdadm --create /dev/md/raid5 --level=5 --raid-devices=3 /dev/md/raid1 /dev/md/raid2 /dev/md/raid3
mdadm -D /dev/md/raid5


If you liked this post, you may also be interested in these...