RAID Redundant Array of Inexpensive Disk aka Redundant Array of Independent Disk is a data storage technology which 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 pf their host but have advantage of being cheap as no dedicated hardware is needed,
- Hardware RAID have their dedicated hardware know as RAID controllers which have its own memory modules & thus doesn’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 going to learn to configure RAID1 on our Linux Servers. You can also read tutorial to configure RADI0 HERE.
RAID (Mirroring) requires at least 2 disks attached to system. It creates exact image of data on both disks, hence know as mirroring. Since same 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.
Firstly we need to install ‘mdadm’ utility on our system, if not installed already
$ yum install mdadm
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 new partition,
- Next type ‘p’ for creating the primary partition (since this is 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.
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]
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
Here, — create /dev/md1 will create md device named ‘/dev/md1’,
— level=mirror, means raid level which here is mirroring (RAID1),
We will now verify our RAID array by running the following command
$ cat /proc/mdstat/dev/sd[b-c]1
For complete details regarding the RAID 1 array, we use the following command
$ mdadm –detail /dev/md1
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.
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
Main reason for using 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 on 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
Now, we will goto /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 RAID1 configurations. If having any doubts/queries, mention them in the comment box below.