How to Configure RAID Using Block Storage on a Linux Server
When you want better storage performance or data protection on your Linux server using multiple disks. This article explains how to configure RAID with block storage.
RAID stands for Redundant Array of Independent Disks. RAID allows you to turn multiple physical hard drives/block storage/SAN storage drives into a single logical hard drive. There are many RAID levels such as RAID 0, RAID 1, RAID 5, RAID 10 etc.
Concepts:
Striping (Achieved with RAID 0): -
If this feature is enabled, data will be written in all available disks randomly. All the disks in the RAID array will be seen as a single logical volume by the server. This is ideal for high performance. Loss of any one disk will result in the failure of the entire volume
Mirroring (achieved with RAID 1): - A copy of the data will be stored on both disks. Data will be written to 2 disks simultaneously. This is ideal for high fault tolerance, however the size of the logical volume is equal to size of 1 disk only.
Parity (Achieved with RAID5,6): - This is method of regenerating lost data from saved parity information. This requires 3 or more disks. This is ideal for fault tolerance as well as high performance
RAID 0:
Features of RAID 0:
-It improves the read write performance by distributing reads and writes to multiple disks.
-it works on stripping data across multiple disks simultaneously,
-RAID 0 is not suitable for data storage because It did not provide Fault Tolerance
-If any disk fail raid is unusable because none of data is duplicated.
-RAID 0 is ideal for non-critical storage of data that have to be read/written at a high speed, such as on an image retouching or video editing

Implementing RAID 0 with block storage
Step1: Install mdadm
yum -y install mdadm (centos/RHEL/fedora)
apt-get install -y mdadm (Ubuntu/debian
Use lsblk or fdisk -l to get the storage devices attached to the server

Here we see 2 SAN/Block storage addons with 50GB each. We will create a 100GB RAID0 array
Step 2: To create RAID Array with disks use following command:
#mdadm --create --verbose /dev/[ RAID array Name or Number] --level=0--raid-devices=2 [Storage Device] [Storage Device]

Verify using cat proc/mdstat

Above output confirms that RAID array md0 under /dev/md0 has been successfully created from two disks (vdb and vdc)
Step 3: Creating a File system for the RAID Array.
>mkfs -t ext4 /dev/md0

Step4: Mount the Filesystem on a created mount point
>mkdir -p /mnt/raid0
>mount /dev/md0 /mnt/raid0
You can see that /mnt/raid0 now has a disk size of 2 disks combined
--------
Filesystem Size Used Avail Use% Mounted on
/dev/md0 99G 61M 94G 1% /mnt/raid0
----------
Step 5: Edit fstab as follows to make the mount permanent
--------
/dev/md0 /mnt/raid0 ext4 defaults 0 0
--------
RAID 1:
Features of RAID 1:
-If a drive fails, the controller uses either the data drive or the mirror drive for data recovery and continuous operation.
-You need at least 2 drives for a RAID 1 array.
-The main disadvantage is that the effective storage capacity is only half of the total drive capacity because all data get written twice.
-RAID-1 is ideal for mission critical storage, for instance for accounting systems. It is also suitable for small servers in which only two data drives will be used.

Implementing RAID 1 with block storage
Step1: Install mdadm
yum -y install mdadm (centos/RHEL/fedora)
apt-get install -y mdadm (Ubuntu/debian
Use lsblk or fdisk -l to get the storage devices attached to the server

Step2: To create RAID Array with disks use following command:
#mdadm --create --verbose /dev/[ RAID array Name or Number] --level=1 --raid-devices=2 [Storage Device] [Storage Device]
Example
mdadm --create --verbose /dev/md1 --level=1 --raid-devices=2 /dev/vdb /dev/vdc

Verify using cat proc/mdstat
-------------
root@raid_demo [~]# cat /proc/mdstat
Personalities : [raid1]
md1 : active raid1 vdc[1] vdb[0]
52362240 blocks super 1.2 [2/2] [UU]
[>....................] resync = 0.4% (215424/52362240) finish=48.4min speed=17952K/sec
-------------
Above output confirms that RAID array md1 under /dev/md1 has been successfully created from two disks (vdb and vdc)
Step3: Make a filesystem from the newly created raid array
>mkfs -t ext4 /dev/md1
Step 4: Mount the filesystem on a mount point
>mkdir -p /mnt/raid1
>mount /dev/md1 /mnt/raid1
----------
root@raid_demo [~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/md1 50G 53M 47G 1% /mnt/raid1
---------
You can see that /mnt/raid1 made from /dev/vdb(50GB) and /dev/vdc(50GB) now has a disk size of 1 disk (50GB)
Step 5: Edit fstab as follows to make the mount permanent
--------
/dev/md1 /mnt/raid0 ext4 defaults 0 0
--------
Verify the details of the array using
mdadm --detail /dev/md1

RAID 5:
Features of RAID 5:
-RAID 5 is the most common secure RAID level. It requires at least 3 drives but can work with up to 16.
-In RAID 5, data strips across multiple drives with distributed parity. The striping with distributed parity means it will split the parity information and stripe data over the multiple disks, which will have good data redundancy.
-Using the parity data, the server can recalculate the data of one of the other data blocks, should those data no longer be available. That means a RAID 5 array can withstand a drive failure without losing data or access to data.

Implementing RAID 5 with block storage
Step1: Install mdadm
yum -y install mdadm (centos/RHEL/fedora)
apt-get install -y mdadm (Ubuntu/debian)
Use lsblk or fdisk -l to get the storage devices attached to the server

Step2: To create RAID Array with disks use following command:
#mdadm --create --verbose /dev/[ RAID array Name or Number] --level=[RAID Level] --raid-devices=[Number of storage devices] [Storage Device] [Storage Device]
>mdadm --create --verbose /dev/md5 --level=5 --raid-devices=3 /dev/vdb /dev/vdc /dev/vdd
Verify using cat proc/mdstat
--------
root@raid_demo [~]# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4]
md5 : active raid5 vdd[3] vdc[1] vdb[0]
104724480 blocks super 1.2 level 5, 512k chunk, algorithm 2 [3/2] [UU_]
[>....................] recovery = 2.2% (1200128/52362240) finish=4.2min speed=200021K/sec
--------
Above output confirms that RAID array md5 under /dev/md5 has been successfully created from two disks (vdb,vdc, and vdd)
Step3: Make a filesystem from the newly created raid array
>mkfs -t ext4 /dev/md5
Step 4: Mount the filesystem on a mount point
>mkdir -p /mnt/raid5
>mount /dev/md1 /mnt/raid5
----------
root@raid_demo [~]# df -h
Filesystem Size Used Avai
l Use% Mounted on
/dev/md5 99G 53M 94G 1% /mnt/raid5
---------
Step 5: Edit fstab as follows to make the mount permanent
--------
/dev/md5 /mnt/raid0 ext4 defaults 0 0
--------
Verify the details of the array
mdadm --detail /dev/md5
