Setting up RAID 1 (Mirroring) using ‘Two Disks’ in Linux – Part 3

RAID Mirroring means an exact clone (or mirror) of the same data writing to two drives. A minimum two number of disks are more required in an array to create RAID1 and it’s useful only, when read performance or reliability is more precise than the data storage capacity.

Create Raid1 in Linux

Setup Raid1 in Linux

Mirrors are created to protect against data loss due to disk failure. Each disk in a mirror involves an exact copy of the data. When one disk fails, the same data can be retrieved from other functioning disk. However, the failed drive can be replaced from the running computer without any user interruption.

Features of RAID 1

  1. Mirror has Good Performance.
  2. 50% of space will be lost. Means if we have two disk with 500GB size total, it will be 1TB but in Mirroring it will only show us 500GB.
  3. No data loss in Mirroring if one disk fails, because we have the same content in both disks.
  4. Reading will be good than writing data to drive.


Minimum Two number of disks are allowed to create RAID 1, but you can add more disks by using twice as 2, 4, 6, 8. To add more disks, your system must have a RAID physical adapter (hardware card).

Here we’re using software raid not a Hardware raid, if your system has an inbuilt physical hardware raid card you can access it from it’s utility UI or using Ctrl+I key.

Read Also: Basic Concepts of RAID in Linux

My Server Setup
Operating System :	CentOS 6.5 Final
IP Address	 :
Hostname	 :
Disk 1 [20GB]	 :	/dev/sdb
Disk 2 [20GB]	 :	/dev/sdc

This article will guide you through a step-by-step instructions on how to setup a software RAID 1 or Mirror using mdadm (creates and manages raid) on Linux Platform. Although the same instructions also works on other Linux distributions such as RedHat, CentOS, Fedora, etc.

Step 1: Installing Prerequisites and Examine Drives

1. As I said above, we’re using mdadm utility for creating and managing RAID in Linux. So, let’s install the mdadm software package on Linux using yum or apt-get package manager tool.

# yum install mdadm		[on RedHat systems]
# apt-get install mdadm 	[on Debain systems]

2. Once ‘mdadm‘ package has been installed, we need to examine our disk drives whether there is already any raid configured using the following command.

# mdadm -E /dev/sd[b-c]
Check RAID on Disks

Check RAID on Disks

As you see from the above screen, that there is no any super-block detected yet, means no RAID defined.

Step 2: Drive Partitioning for RAID

3. As I mentioned above, that we’re using minimum two partitions /dev/sdb and /dev/sdc for creating RAID1. Let’s create partitions on these two drives using ‘fdisk‘ command and change the type to raid during partition creation.

# fdisk /dev/sdb
Follow the below instructions
  1. Press ‘n‘ for creating new partition.
  2. Then choose ‘P‘ for Primary partition.
  3. Next select the partition number as 1.
  4. Give the default full size by just pressing two times Enter key.
  5. Next press ‘p‘ to print the defined partition.
  6. Press ‘L‘ to list all available types.
  7. Type ‘t‘to choose the partitions.
  8. Choose ‘fd‘ for Linux raid auto and press Enter to apply.
  9. Then again use ‘p‘ to print the changes what we have made.
  10. Use ‘w‘ to write the changes.
Create Disk Partitions

Create Disk Partitions

After ‘/dev/sdb‘ partition has been created, next follow the same instructions to create new partition on /dev/sdc drive.

# fdisk /dev/sdc
Create Second Partitions

Create Second Partitions

4. Once both the partitions are created successfully, verify the changes on both sdb & sdc drive using the same ‘mdadm‘ command and also confirm the RAID type as shown in the following screen grabs.

# mdadm -E /dev/sd[b-c]
Verify Partitions Changes

Verify Partitions Changes

Check RAID Type

Check RAID Type

Note: As you see in the above picture, there is no any defined RAID on the sdb1 and sdc1 drives so far, that’s the reason we are getting as no super-blocks detected.

Step 3: Creating RAID1 Devices

5. Next create RAID1 Device called ‘/dev/md0‘ using the following command and verity it.

# mdadm --create /dev/md0 --level=mirror --raid-devices=2 /dev/sd[b-c]1
# cat /proc/mdstat
Create RAID Device

Create RAID Device

6. Next check the raid devices type and raid array using following commands.

# mdadm -E /dev/sd[b-c]1
# mdadm --detail /dev/md0
Check RAID Device type

Check RAID Device type

Check RAID Device Array

Check RAID Device Array

From the above pictures, one can easily understand that raid1 have been created and using /dev/sdb1 and /dev/sdc1 partitions and also you can see the status as resyncing.

Step 4: Creating File System on RAID Device

7. Create file system using ext4 for md0 and mount under /mnt/raid1.

# mkfs.ext4 /dev/md0
Create RAID Device Filesystem

Create RAID Device Filesystem

8. Next, mount the newly created filesystem under ‘/mnt/raid1‘ and create some files and verify the contents under mount point.

# mkdir /mnt/raid1
# mount /dev/md0 /mnt/raid1/
# touch /mnt/raid1/tecmint.txt
# echo "tecmint raid setups" > /mnt/raid1/tecmint.txt
Mount Raid Device

Mount Raid Device

9. To auto-mount RAID1 on system reboot, you need to make an entry in fstab file. Open ‘/etc/fstab‘ file and add the following line at the bottom of the file.

/dev/md0                /mnt/raid1              ext4    defaults        0 0
Raid Automount Device

Raid Automount Device

10. Run ‘mount -a‘ to check whether there are any errors in fstab entry.

# mount -av
Check Errors in fstab

Check Errors in fstab

11. Next, save the raid configuration manually to ‘mdadm.conf‘ file using the below command.

# mdadm --detail --scan --verbose >> /etc/mdadm.conf
Save Raid Configuration

Save Raid Configuration

The above configuration file is read by the system at the reboots and load the RAID devices.

Step 5: Verify Data After Disk Failure

12. Our main purpose is, even after any of hard disk fail or crash our data needs to be available. Let’s see what will happen when any of disk disk is unavailable in array.

# mdadm --detail /dev/md0
Raid Device Verify

Raid Device Verify

In the above image, we can see there are 2 devices available in our RAID and Active Devices are 2. Now let us see what will happen when a disk plugged out (removed sdc disk) or fails.

# ls -l /dev | grep sd
# mdadm --detail /dev/md0
Test RAID Devices

Test RAID Devices

Now in the above image, you can see that one of our drive is lost. I unplugged one of the drive from my Virtual machine. Now let us check our precious data.

# cd /mnt/raid1/
# cat tecmint.txt
Verify RAID Data

Verify RAID Data

Did you see our data is still available. From this we come to know the advantage of RAID 1 (mirror). In next article, we will see how to setup a RAID 5 striping with distributed Parity. Hope this helps you to understand how the RAID 1 (Mirror) Works.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Babin Lonston

I'm Working as a System Administrator for last 10 year's with 4 years experience with Linux Distributions, fall in love with text based operating systems.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

68 Responses

  1. ruwan says:

    Thanks. Working perfectly…

  2. Csaba says:

    I need help please:

    sudo mdadm —-create /dev/md0 -—level=mirror -—raid-devices=2 /dev/sd[cd]1
    mdadm: An option must be given to set the mode before a second device
    (/dev/md0) is listed

  3. Rajarao says:

    Thank you ! Excellent Tutorials! I was able to understand with no tech background, Do you have any AWS questions dump for Solution Architect Associate exam.

  4. Swaraj says:

    mdadm E showing raid super block already exists. What is the procedure to clean it and use device for another raid level?

  5. Amar G says:

    Thank you so much Bobin. I always follow when I have any doubt and I want to clear that. Really your lots of articles are very useful for me.

  6. Vishal Bajpai says:

    Why Raid is configured of partitioned disk, if we can do it on disk itself? Why extra efforts in creating partition?

  7. Clark kent says:

    It is possible to RAID1 my existing HDD? I have 1 HDD running now I want to add HDD as mirror.

    • Babin Lonston says:


      No, You required to backup your data’s to create a DM device. Then try to setup a Raid 1.

      Thanks & Regards,
      Babin Lonston

  8. charly says:

    I use this tutorial all the time. THANKS!

    Here are some instructions for Debian at least, to delete a created raid and start from scratch (I had to, after messing up my NAS Debian)

  9. Arun says:

    Hello Babin,

    It is possible to create RAID configuration on ISCSI blocks?

    • Hi Arun,

      It’s possible, But the concept of RAID is failover. When a disk failed in the array it will be available.

      In real time environments, iSCSI blocks are created on top of some disk array which already running with Hardware RAID.

      Storage –> Disk Array in a RAID –> Create a iSCSI block –> Presented to your server.

      Thanks & Regards,
      Bobin Lonston

  10. Volkan Paksoy says:


    Thanks for the article, it’s been helpful to me to set up a RAID1. For some reason it automatically renamed it to /dev/md127. After I modified the fstab file accordingly it worked fine.

    A problem happens though when I try to test it. I’m using a physical machine. I shutdown the machine and unplugged one of the drives but it didn’t reboot properly. I had to connect a monitor and keyboard as I think it booted into a emergency mode or something like that, SSH is not running at that stage.

    Anyway, when I run mdadm –detail /dev/md127 the state is inactive.
    So in a real world scenario how will I be able to replace a disk and add it to the RAID? Any ideas?

    Thanks again for the article.

    • Volkan Paksoy says:

      In my experience unplugging the drive didn’t work. But if I run this command before unplugging.

      # mdadm --manage /dev/md0 --remove /dev/sdb1

      then it boots just fine and the RAID becomes degraded. Then a new disk can be added.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.