Linux 101 : Software RAID - mdadm, fdsisk -

Linux has a software raid that allows us to create our own RAID devices without the need for specialized hardware.

Hard drives from different manufacturers, that are for example 1GB in size, could actually be a couple of megabytes off. 
For example hard drive, while being advertised as having 1GB might have 1030MB and another 1GB hard drive might have 1024MB.

Disk sizes:

When a 1030MB -real size value- ( 1 GB - advertised valuedisk fails and we want to use a spare that is 1024MB -real size value- 1 GB - advertised value) to replace it, it is not going to work because the sizes are different.

A simple solution it to create the same size partition inside the running disks and the spares to make sure that they match.

Creating a "Linux RAID" partition:

Below is an "fdisk" example of creating the RAID partition for a partition ''/dev/sda1", we apply the same process for our RAID partitions "/dev/sda2" and "/dev/sdb2':

Using the "lsblk" tool:

To can see the drives in our system, using the below command:

We create two partitions using the fsdisk tool, and we give them partition the same size, "sda2" and "sdb2".

We then pick the partition type "
fd: Linux raid" in fdisk by typing "t" in the interactive menu.
We would see the message in fsdisk that the partition type changed to "Linux raid" ( The example above shows us how to create Linux RAID partitions using fdisk )

We could use lsblk to check our newly created partitions "sda2" and "sdb2":

Creating the RAID array:

We use the below command to create a RAID-1 array.
The RAID device is named "/dev/md0":

"/dev/md0" that the first RAID device. If we create a the second one, it will be named "/dev/md1".

The details could be seen using one of the below commands:


Now we could use the "/dev/md0" RAID device as a hard drive in our system.

Persisting beyond reboot:

To be able to use our device "/dev/md0" after each reboot, we would need to write its configuration in the "/etc/mdadm.conf" file as below:

"/dev/md0" will be created every time we reboot the machine.

Creating a filesystem on the RAID device:

To be able to use our newly created RAID device, we create an "ext4" filesystem on it using the below command:

We check our RAID device using the below command:

We can mount our device "/dev/md0" the same way we would mount a normal partition using the "
mount" command on a mountpoint that we can create using the "mkdir" command.

Automatic mounting and the "/etc/fstab" file:

We can also add the below to the "/etc/fstab" file for automatic mounting at boot time:


Leave as a comment: