Tag Archives: Redhat Linux

How to Configure RAID1 in Linux

RAID1 means creating an array of disks with mirroring feature. Which means the similar data will be copied on the other member disk of the array. Lets start to understand.

We need to have minimum two disks for RAID1.

  1. I have /dev/sdb and /dev/sdc in this example.
  2. Install mdadm package on your server.
  3. Verify the disk for any previous RAID configuration.

raid1-1.JPG

  1. Make partition for both disks using fdisk command and set the type as fd (Linux Raid Autodetect).
  2. Create a RAID1 device name /dev/md0.

raid1-2

3. Verify the disk for RAID configuration.

raid1-3

raid1-4

4. Create file system for md0 and mount it on the server.

In the above example, we have mounted the raid device md0 and created a test file.

 5. Make sure to save the configuration manually because RAID do not have a config      file by default. If we skip this step RAID device will not be in md0, it will take some random number.

mdadm –detail –scan –verbose >> /etc/mdadm.conf; cat /etc/mdadm.conf

6. Update the /etc/fstab for persistent file system mount.

Above steps were to create a RAID 1 Device ( Mirror), Now lets trigger failure of one disk and check the availability of data.

1. Below screenshot shows one disk in removed state in the RAID1 device we created in above example. I actually removed one drive from the VM to test the data availability.

Raid1-after failure.

2. Check the data in the File system mounted on this /dev/md0, we should have the data there.

Raid1-test data

This is the expected behavior of RAID1 device. If one drives failed, we must have the access to data because of mirror feature of RAID1.

How to rebuild a RAID Device:

Normally in situation like faulty drive, we may need to rebuild the array by removing the faulty drive and adding the new drive. Lets proceed with the above situation where one of the drive is removed and now we will add new drive and going to rebuild the array.

  1. Check the faulty drive using:#mdadm –detail /dev/md OR  #cat /proc/mdstat
  2. remove the faulty drive: mdadm –manage /dev/md0 -r /dev/sdc1
  3. Add the new drive: mdadm –manage /dev/md0 -a /dev/sdd1 Raid1-rebuild arrayDid you notice the state “spare rebuilding”? it is quite clear from this that the new drive we added is being added into RAID device. Once it get complete, it will going to change the state to “active/sync”
  4. Check the array using mdadm –detail /dev/md0

 

How to remove a RAID Device:

Raid1-remove RAID

The process for creating other RAID level will be the same, you just need to mention the level and raid-devices while create the RAID devices. The most commonly used are RAID0, RAID1, RAID5. The later one is the hybrid model of 0 and 1 which provides both features of high performance using striping and data availability using parity.