Configuring RAID1 (Mirroring) on CentOS/RHEL
RAID aka 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 will be configuring RAID1 on our Linux Servers. You can also read tutorial to configure RADI0 HERE.
(Also Read: Resizing LVM made easy : A Beginner’s Guide)
RAID1 (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
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
- 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
Now that we partitioned both HDDs, we will create RAID array (aka md device) named ‘/dev/md1’ using the following command
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
For complete details regarding the RAID 1 array, we use the following command
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
& next we will mount it on /data,
But this is only a temporary mount & will not survive a reboot. So we will make an entry into /etc/fstab
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
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
Now we can either remove on of the drives or we can simulate a disk failure with the following command
Let’s check the status of RAID1 now,
Now, we will goto /data & verify the files there,
We can see that all our data files are intact with all the files & folders present.
This completes our tutorial on configuring RAID1 . If having any doubts/queries, mention them in the comment box below.