How To Create RAID In Linux

In this article we are going to discuss how to create raid in linux.

 RAID is a method of using multiple hard drives to act as one and purposes of data redundancy, performance improvement, or both

Purposes of RAID (Redundant Array of Inexpensive Disks):

  • Expand drive capacity: RAID 0. If you have 2 x 500 GB HDD then total space become 1 TB.

  • Prevent data loss in case of drive failure: For example RAID 1, RAID 5, RAID 6, and RAID 1+0 or 0+1.

We are going to creating a software RAID

Step 1: Creating a Partition

Creating a physical volume:

#fdisk -c /dev/sdb

press “p” (for print)

press “n” for new partition

press “p” for primary partition “e” for extended partition

press “t” for partition ID

give “fd” for RAID partition

press “w” for save and quit

Sample Output:

[root@localhost ~]# fdisk -l | grep -i “/dev/sd”

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors

/dev/sda1   *        2048      616447      307200   83  Linux

/dev/sda2          616448     4810751     2097152   82  Linux swap / Solaris

/dev/sda3         4810752    41943039    18566144   83  Linux

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors

Disk /dev/sdc: 1073 MB, 1073741824 bytes, 2097152 sectors

Disk /dev/sdd: 1073 MB, 1073741824 bytes, 2097152 sectors

Disk /dev/sde: 1073 MB, 1073741824 bytes, 2097152 sectors

[root@localhost ~]# fdisk -c /dev/sdb

Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.

Be careful before using the write command.

Command (m for help): n

Partition type:

   p   primary (0 primary, 0 extended, 4 free)

   e   extended

Select (default p): p

Partition number (1-4, default 1): 1

First sector (2048-2097151, default 2048):

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-2097151, default 2097151):

Using default value 2097151

Partition 1 of type Linux and of size 1023 MiB is set

Command (m for help): t

Selected partition 1

Hex code (type L to list all codes): fd

Changed type of partition ‘Linux’ to ‘Linux raid autodetect’

Command (m for help): p

Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors

Units = sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk label type: dos

Disk identifier: 0x0449f63b

   Device Boot      Start         End      Blocks   Id  System

/dev/sdb1            2048     2097151     1047552   fd  Linux raid autodetect

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

 

Note: We can create a RAID without partitioning of the disk. For RAID 0, need 2 disks.

Step 2: Create A RAID

#mdadm –create /dev/md0 –level=0 –raid-devices=2 /dev/sdb1 /dev/sdc1

Sample Output:

mdadm: Defaulting to version 1.2 metadata

mdadm: array /dev/md0 started.

 

Step 3: Verify The RAID

#mdadm –detail /dev/md0

Sample Output:

[root@localhost ~]# mdadm –detail /dev/md0

/dev/md0:

           Version : 1.2

     Creation Time : Fri Sep 17 13:30:58 2021

        Raid Level : raid0

        Array Size : 2091008 (2042.00 MiB 2141.19 MB)

      Raid Devices : 2

     Total Devices : 2

       Persistence : Superblock is persistent

 

       Update Time : Fri Sep 17 13:30:58 2021

             State : clean

    Active Devices : 2

   Working Devices : 2

    Failed Devices : 0

     Spare Devices : 0

 

        Chunk Size : 512K

 

Consistency Policy : none

 

              Name : localhost.localdomain:0  (local to host localhost.localdomain)

              UUID : 243650f8:d2c38bdc:b0ef513e:0edd6d6b

            Events : 0

 

    Number   Major   Minor   RaidDevice State

       0       8       17        0      active sync   /dev/sdb1

       1       8       33        1      active sync   /dev/sdc1

 

# cat /proc/mdstat
Personalities : [raid6] [raid5] [raid4] [raid0]
md0 : active raid0 sdc1[1] sdb1[0]
      2091008 blocks super 1.2 512k chunks
 
unused devices:
 
This means you have successfully created RAID 0.