Creating Software RAID0 (Stripe) on ‘Two Devices’ Using ‘mdadm’ Tool in Linux – Part 2

RAID is Redundant Array of Inexpensive disks, used for high availability and reliability in large scale environments, where data need to be protected than normal use. Raid is just a collection of disks in a pool to become a logical volume and contains an array. A combine drivers makes an array or called as set of (group).

RAID can be created, if there are minimum 2 number of disk connected to a raid controller and make a logical volume or more drives can be added in an array according to defined RAID Levels. Software Raid are available without using Physical hardware those are called as software raid. Software Raid will be named as Poor man raid.

Setup RAID0 in Linux
Setup RAID0 in Linux

Main concept of using RAID is to save data from Single point of failure, means if we using a single disk to store the data and if it’s failed, then there is no chance of getting our data back, to stop the data loss we need a fault tolerance method. So, that we can use some collection of disk to form a RAID set.

What is Stripe in RAID 0?

Stripe is striping data across multiple disk at the same time by dividing the contents. Assume we have two disks and if we save content to logical volume it will be saved under both two physical disks by dividing the content. For better performance RAID 0 will be used, but we can’t get the data if one of the drive fails. So, it isn’t a good practice to use RAID 0. The only solution is to install operating system with RAID0 applied logical volumes to safe your important files.

  1. RAID 0 has High Performance.
  2. Zero Capacity Loss in RAID 0. No Space will be wasted.
  3. Zero Fault Tolerance ( Can’t get back the data if any one of disk fails).
  4. Write and Reading will be Excellent.

Requirements

Minimum number of disks are allowed to create RAID 0 is 2, but you can add more disk but the order should be twice as 2, 4, 6, 8. If you have a Physical RAID card with enough ports, you can add more disks.

Here we are not using a Hardware raid, this setup depends only on Software RAID. If we have a physical hardware raid card we can access it from it’s utility UI. Some motherboard by default in-build with RAID feature, there UI can be accessed using Ctrl+I keys.

If you’re new to RAID setups, please read our earlier article, where we’ve covered some basic introduction of about RAID.

  1. Introduction to RAID and RAID Concepts
My Server Setup
Operating System :	CentOS 6.5 Final
IP Address	 :	192.168.0.225
Two Disks	 :	20 GB each

This article is Part 2 of a 9-tutorial RAID series, here in this part, we are going to see how we can create and setup Software RAID0 or striping in Linux systems or servers using two 20GB disks named sdb and sdc.

Step 1: Updating System and Installing mdadm for Managing RAID

1. Before setting up RAID0 in Linux, let’s do a system update and then install ‘mdadm‘ package. The mdadm is a small program, which will allow us to configure and manage RAID devices in Linux.

# yum clean all && yum update
# yum install mdadm -y
install mdadm in linux
Install mdadm Tool

Step 2: Verify Attached Two 20GB Drives

2. Before creating RAID 0, make sure to verify that the attached two hard drives are detected or not, using the following command.

# ls -l /dev | grep sd
Check Hard Drives in Linux
Check Hard Drives

3. Once the new hard drives detected, it’s time to check whether the attached drives are already using any existing raid with the help of following ‘mdadm’ command.

# mdadm --examine /dev/sd[b-c]
Check RAID Devices in Linux
Check RAID Devices

In the above output, we come to know that none of the RAID have been applied to these two sdb and sdc drives.

Step 3: Creating Partitions for RAID

4. Now create sdb and sdc partitions for raid, with the help of following fdisk command. Here, I will show how to create partition on sdb drive.

# fdisk /dev/sdb

Follow below instructions for creating partitions.

  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 value by just pressing two times Enter key.
  5. Next press ‘P‘ to print the defined partition.
Create Partitions in Linux
Create Partitions

Follow below instructions for creating Linux raid auto on partitions.

  1. Press ‘L‘ to list all available types.
  2. Type ‘t‘to choose the partitions.
  3. Choose ‘fd‘ for Linux raid auto and press Enter to apply.
  4. Then again use ‘P‘ to print the changes what we have made.
  5. Use ‘w‘ to write the changes.
Create RAID Partitions
Create RAID Partitions in Linux

Note: Please follow same above instructions to create partition on sdc drive now.

5. After creating partitions, verify both the drivers are correctly defined for RAID using following command.

# mdadm --examine /dev/sd[b-c]
# mdadm --examine /dev/sd[b-c]1
Verify RAID Partitions
Verify RAID Partitions

Step 4: Creating RAID md Devices

6. Now create md device (i.e. /dev/md0) and apply raid level using below command.

# mdadm -C /dev/md0 -l raid0 -n 2 /dev/sd[b-c]1
# mdadm --create /dev/md0 --level=stripe --raid-devices=2 /dev/sd[b-c]1
  1. -C – create
  2. -l – level
  3. -n – No of raid-devices

7. Once md device has been created, now verify the status of RAID Level, Devices and Array used, with the help of following series of commands as shown.

# cat /proc/mdstat
Verify RAID Level
Verify RAID Level
# mdadm -E /dev/sd[b-c]1
Verify RAID Device
Verify RAID Device
# mdadm --detail /dev/md0
Verify RAID Array
Verify RAID Array

Step 5: Assiging RAID Devices to Filesystem

8. Create a ext4 filesystem for a RAID device /dev/md0 and mount it under /dev/raid0.

# mkfs.ext4 /dev/md0
Create ext4 Filesystem in Linux
Create ext4 Filesystem

9. Once ext4 filesystem has been created for Raid device, now create a mount point directory (i.e. /mnt/raid0) and mount the device /dev/md0 under it.

# mkdir /mnt/raid0
# mount /dev/md0 /mnt/raid0/

10. Next, verify that the device /dev/md0 is mounted under /mnt/raid0 directory using df command.

# df -h

11. Next, create a file called ‘tecmint.txt‘ under the mount point /mnt/raid0, add some content to the created file and view the content of a file and directory.

# touch /mnt/raid0/tecmint.txt
# echo "Hi everyone how you doing ?" > /mnt/raid0/tecmint.txt
# cat /mnt/raid0/tecmint.txt
# ls -l /mnt/raid0/
Verify Mount Device
Verify Mount Device

12. Once you’ve verified mount points, it’s time to create an fstab entry in /etc/fstab file.

# vim /etc/fstab

Add the following entry as described. May vary according to your mount location and filesystem you using.

/dev/md0                /mnt/raid0              ext4    defaults         0 0
Add Device to Fstab
Add Device to Fstab

13. Run mount ‘-a‘ to check if there is any error in fstab entry.

# mount -av
Check Errors in Fstab
Check Errors in Fstab

Step 6: Saving RAID Configurations

14. Finally, save the raid configuration to one of the file to keep the configurations for future use. Again we use ‘mdadm’ command with ‘-s‘ (scan) and ‘-v‘ (verbose) options as shown.

# mdadm -E -s -v >> /etc/mdadm.conf
# mdadm --detail --scan --verbose >> /etc/mdadm.conf
# cat /etc/mdadm.conf
Save RAID Configurations
Save RAID Configurations

That’s it, we have seen here, how to configure RAID0 striping with raid levels by using two hard disks. In next article, we will see how to setup RAID5.

If you read this far, tweet to the author to show them you care. Tweet a thanks
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.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

38 thoughts on “Creating Software RAID0 (Stripe) on ‘Two Devices’ Using ‘mdadm’ Tool in Linux – Part 2”

  1. So, when messing around with this, how does one undo the changes made? It did not work, but not I can’t stop it.

    mdadm: Cannot get exclusive access to /dev/md0:Perhaps a running process, mounted filesystem, or active volume group?

    Thoughts?

    Reply
  2. In step 6 you also need to add “update-initramfs -u” if you are running a Debian install. otherwise, the steps are the same. if you don’t run that command, you will boot into emergency mode.

    Thanks for the guide!

    Reply
  3. I am having trouble with setting up my RAID 0 Array following this guide and everything goes as expected until I look at the available space when I am done. I am only seeing half of my drive capacity. I am running Plex Media Server on Centos7.

    The way I initially set this up was I use a 120gb SSD for the OS, I use a second 120gb SSD for transcoding video. I initially set this server up with Software RAID 5 using 12 old 500gb hard drives, after having at least 2 drives fail, I ripped them all out and purchased 2 new 4TB WD drives.

    With some help, we cleared out the software raid info and got the server ready for the 2 new drives. I ran through this guide step by step and at the end, I see 4TB of available space. Any ideas on what I am doing wrong?

    Reply
  4. I am a Linux newbie and I have never used Linux professionally.

    I have have been using Linux only on my home PC and via virtualbox labs, but I must admin that through this website I can see the light at the end of the tunnel and I am feeling more confident to accept a Linux sysadmin job now.

    As for Babin you are the main man and I would like you to do a session covering how to get the following right on a virtualbox lab, confirgure DNS, DHCP and VPN for both CentOS and Ubuntu

    Thank you all for such an amazing job.

    Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.