RAID aka Redundant Array of Inexpensive Disk aka Redundant Array of Independent Disk is a data storage technology that uses a number of disks & uses them as a single logical storage unit to provide us with data redundancy, performance or both.

There are two ways to implementing RAID technology into your IT environment i.e.

  • Software RAID can be used with most of the modern Linux distributions but they have low performance as they use the resources of their host but have the advantage of being cheap as no dedicated hardware is needed,
  • Hardware RAID has their dedicated hardware know as RAID controllers which have their own memory modules & thus don’t use the resources of the host. They have good performance but are very costly to use.

We are going to discuss software RAID for this tutorial. Both software RAID & Hardware RAID have various levels in which they are configured, based on the requirements like performance, data redundancy, etc.

In this tutorial, we will be configuring RAID1 on our CentOS Servers. You can also read tutorials to configure RAID0 HERE.

(Also Read: Resizing LVM made easy : A Beginner’s Guide)

(Also Read: Cloning Disks using dd & cat commands for Linux systems)


RAID 1

RAID1 (Mirroring) requires at least 2 disks attached to the system. It creates an exact image of data on both disks, hence knows as mirroring. Since some data is stored on both drives, data capacity is cut to half but you will have good read performance & data redundancy in case of a disk failure.


Configuring RAID1 on CentOS

STEP 1

Firstly we need to install ‘mdadm’ utility on our system, if not installed already

$ yum install mdadm

Step 2

After installing ‘mdadm’, we will prepare our disks sdb & sdc for RAID configuration with the help of ‘fdisk’

  • Firstly we will prepare /dev/sdb disk for LVM, start by

    $ fdisk /dev/sdb

  • Type ‘n’ for creating a new partition,
  • Next type ‘p’ for creating the primary partition (since this is a new disk, partition number will be 1 )
  • Nest for First cylinder value & last cylinder value, press enter to use default values i.e. full HDD space
  • Type ‘t’ for accessing the partition followed by ‘1’ (partition number)
  • Now, this is the part where we will enter the partition id for creating RAID i.e. 'fd’. Type ‘fd’ now & press ‘w’ to write changes.

The same process is to be followed for /dev/sdc as well. When both disks have been partitioned, we can examine them using

$ mdadm –examine  /dev/sd[b-c]

configuring raid1 centos

Step 3

Now that we partitioned both HDDs, we will create RAID array (aka md device) named ‘/dev/md1’ using the following command

mdadm --create /dev/md1 --level=mirror --raid-devices=2 /dev/sd[b-c]1

configuring raid1 centos

Here, -- create /dev/md1 will create md device named ‘/dev/md1’,

-- level=mirror, means raid level which here is mirroring (RAID1),

STEP 4

We will now verify our RAID array by running the following command

$ cat /proc/mdstat/dev/sd[b-c]1

configuring raid1 centos

For complete details regarding the RAID 1 array, we use the following command

$ mdadm --detail /dev/md1

raid1

 

STEP 5

RAID array is ready but still can’t be used as we have not assigned it a filesystem & have not mounted it on our system. So we will assign a filesystem first using ‘mkfs’ command

$ mkfs.ext4 /dev/md1

& next we will mount it on /data,

$ mkdir /data
$ mount /dev/md1 /data

But this is only a temporary mount & will not survive a reboot. So we will make an entry into /etc/fstab

$ vi /etc/fstab

/dev/md1                /data              ext4    defaults         0 0

Save & exit the file. Our RAID array is now permanently mounted to /data.

STEP 6

Lastly, we will create backup of the RAID configuration in order to use it further

$ mdadm -E -s -v >> /etc/mdadm.conf
$ mdadm --detail --scan --verbose >> /etc/mdadm.conf
$ cat /etc/mdadm.conf

STEP 7

The main reason for using the RAID1 array is that it provides data redundancy in case of a disk failure. We will simulate a disk failure & then verify data. But first, let’s put some files in /data

$ mkdir testing
$ touch new.txt
$ echo "This is a test data file" > test.txt

Now we can either remove one of the drives or we can simulate a disk failure with the following command

$ mdadm --manage --set-faulty /dev/md1 /dev/sdc1

Let’s check the status of RAID1 now,

$ mdadm --detail /dev/md1

 

configuring raid1 centos

Now, we will go to /data & verify the files there,

$ cd /data
$ cat test.txt
This is a test data file

We can see that all our data files are intact with all the files & folders present.

This completes our tutorial on configuring  RAID1 on CentOS. If having any doubts/queries, mention them in the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter

Linux TechLab is thankful for your continued support.