We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – Configure Software RAID on Rocky Linux 8|AlmaLinux 8 using Mdadm

Learn how to – Configure Software RAID on Rocky Linux 8|AlmaLinux 8 using Mdadm.

Welcome to this guide on how to configure Software RAID on Rocky Linux 8 | RHEL 8 using mdadm. RAID also known as a Redundant array of independent/inexpensive disks is used to combine multiple disks into an array with better performance than that of one large disk. These disks are preferred due to resilience, high performance and help avoid a single point of failure in a disk set.

Configure Software RAID on Rocky Linux 8

Configure Software RAID on RHEL 8

RAID works in a minimum of two or more devices whereby when data is written, it will be spread across multiple disks thus guaranteeing high data availability from multiple disks. There are two types of RAID:

  • Software RAID – This comes with the MD(multiple driver), to create and manage the it, we can use “mdadm” utility.
  • Hardware RAID – This is a PCI or PCI-E card or integrated on the motherboard. They have their own BIOS inbuild in it, they are configured before an Operating System is installed on the RAID
  • Firmware RAID – It is also known as ATARAID,.This is basically a type of software RAID where the RAID sets can be configured using a firmware-based menu, normally hooks into the BIOS, allowing you to boot from its RAID sets.

RAID supports configurations including run levels 0, 1, 4, 5, 6, 10, and linear. These run levels are elaborated in the table below.

RAID-LEVEL METHOD USED MINIMUM DISKS USE PROS CONS
0 Striping 2 Heavy read operations High Performance Data will be lost if one disk fails
1 Mirroring 2 Used for application servers Fault tolerance and high read performance Little lag in write OPS, Reduced storage 1/2.
5 Striping & Parity 3 Can be used for application and normal file Storage Speed and fault tolerance Little lag in writing OPS, Reduced storage 1/3.
6 Striping & Double parity 4 Application servers & large file Storage Has an extra level of redundancy with high-speed performance Low write performance, reduced storage
10(1+0) Both Striping & Mirroring 4 Used in highly utilized Database Servers Write performance and strong fault tolerance It has reduced storage 1/2, offers limited scalability.

The Liner RAID configuration groups drive to create a larger virtual disk, here when any member drive fails, the whole array cannot be used. and the total capacity of members makes the capacity of the disk.

The Software RAID has the following features:

  • Backgrounded array reconstruction using idle system resources
  • Multithreaded design
  • Automatic correction of bad sectors on disks in an array
  • Hot-swappable drive support
  • Portability of arrays between Linux machines without reconstruction
  • Takeover supports RAID level converting, such as RAID0 to RAID6
  • Resync checkpointing so that if you reboot your computer during a resync, at startup the resync will pick up where it left off and not start all over again
  • Automatic CPU detection to take advantage of certain CPU features such as streaming Single Instruction Multiple Data (SIMD) support
  • Regular consistency checks of RAID data to ensure the health of the array

Now we are set to dive in and enjoy the amazing features associated with Software RAID on Rocky Linux 8 | RHEL 8.

Step 1 – Create RAID Partitions on Disks

To set up any of the run levels, you need at least two disks/partitions. Check the available disks on your system as below.

lsblk

Sample Output:

NAME        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sr0          11:0    1  9.2G  0 rom  
vda         252:0    0   40G  0 disk 
├─vda1      252:1    0    1G  0 part /boot
└─vda2      252:2    0   39G  0 part 
  ├─rl-root 253:0    0   35G  0 lvm  /
  └─rl-swap 253:1    0    4G  0 lvm  [SWAP]
vdb         252:16   0   10G  0 disk 
vdc         252:32   0   10G  0 disk 
vdd         252:48   0   10G  0 disk 
vde         252:64   0   10G  0 disk 

In this guide, we have 4 disks attached vdb, vdc, vdd, and vde each with 10GB storage size. Now create a RAID partition on all the disks. Here, we’ll use the parted.

Install parted on your system.

sudo dnf install parted

Switch to the root user:

sudo su -

Set the partition type(gpt) on each disk as below.

parted --script /dev/vdb "mklabel gpt"
parted --script /dev/vdc "mklabel gpt"
parted --script /dev/vdd "mklabel gpt"
parted --script /dev/vde "mklabel gpt"

Now create a partition on the disks and set the file type to EXT4.

parted --script /dev/vdb "mkpart primary ext4 0% 100%"
parted --script /dev/vdc "mkpart primary ext4 0% 100%"
parted --script /dev/vdd "mkpart primary ext4 0% 100%"
parted --script /dev/vde "mkpart primary ext4 0% 100%"

Once the partitions have been created, set it as a RAID partition.

parted --script /dev/vdb "set 1 raid on"
parted --script /dev/vdc "set 1 raid on"
parted --script /dev/vdd "set 1 raid on"
parted --script /dev/vde "set 1 raid on"

Check the partition table created.

parted --script /dev/vdb "print"

Sample output:

Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 10.7GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
 1      1049kB  10.7GB  10.7GB      ext4     primary  raid

Step 2 – Setup Software RAID on Rocky Linux 8 | RHEL 8

Once the partitions have been created, we are set to set up a Software RAID. In this guide, we will use the mdadmtool to create and manage the RAID.

Install mdadm on Rocky Linux 8 | RHEL 8.

dnf install mdadm -y

Now the basic syntax used by mdadmis as below.

mdadm [mode] <raiddevice> [options] <component-devices>

In the command:

  • mode – specifies the operation to be done. This includes;
    • Build (-B, –build) – builds an array that doesn’t have per-device metadata (superblocks).
    • Assemble (-A, –assemble) – used to assemble components of a previously created array into an active array.
    • Create (-C, –create) – used to create a new array with per-device metadata (superblocks).
    • Grow (-G, –grow) – used to grow/shrink an array, or reshape it.
    • Follow/Monitor (-F, –follow, –monitor) – monitor one or more md devices and act on any state changes
    • Auto-detect (–auto-detect) – this mode does not act on a array, but rather it requests the Linux Kernel to activate any auto-detected arrays.
    • Other modes include Misc, Manage

To create a software RAID level 10 using the four disks, we will use the command:

mdadm --create /dev/md0 --level=10 --raid-devices=4 /dev/vd[bcde]

The command can also be shortened as below.

mdadm -C /dev/md0 -l raid10 -n=4 /dev/vd[bcde]

In the above command:

  • -l, –level=specifies the RAID level which can be one of the levels; linear, raid0, 0, stripe, raid1, 1, mirror, raid4, 4, raid5, 5, raid6, 6, raid10, 10, multipath
  • -n, –raid-devices is the number of active devices in the array.

Now proceed as below to create the RAID.

mdadm: partition table exists on /dev/vdb
mdadm: partition table exists on /dev/vdb but will be lost or
       meaningless after creating array
mdadm: partition table exists on /dev/vdc
mdadm: partition table exists on /dev/vdc but will be lost or
       meaningless after creating array
mdadm: partition table exists on /dev/vdd
mdadm: partition table exists on /dev/vdd but will be lost or
       meaningless after creating array
mdadm: partition table exists on /dev/vde
mdadm: partition table exists on /dev/vde but will be lost or
       meaningless after creating array
Continue creating array? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

Now check the RAID status:

$ mdadm --detail /dev/md0
/dev/md0:
           Version : 1.2
     Creation Time : Fri Jan 28 03:33:16 2022
        Raid Level : raid10
        Array Size : 20953088 (19.98 GiB 21.46 GB)
     Used Dev Size : 10476544 (9.99 GiB 10.73 GB)
      Raid Devices : 4
     Total Devices : 4
       Persistence : Superblock is persistent

       Update Time : Fri Jan 28 03:35:00 2022
             State : clean 
    Active Devices : 4
   Working Devices : 4
    Failed Devices : 0
     Spare Devices : 0

            Layout : near=2
        Chunk Size : 512K

Consistency Policy : resync

              Name : localhost.localdomain:0  (local to host localhost.localdomain)
              UUID : 089d8e15:403e261e:dbbee899:36a357b2
            Events : 17

    Number   Major   Minor   RaidDevice State
       0     252       16        0      active sync set-A   /dev/vdb
       1     252       32        1      active sync set-B   /dev/vdc
       2     252       48        2      active sync set-A   /dev/vdd
       3     252       64        3      active sync set-B   /dev/vde

Get a detailed information list using the command:

mdadm --examine /dev/vd[bcde]

Alternatively, check the status of the RAID using the command:

$ cat /proc/mdstat
Personalities : [raid10] 
md0 : active raid10 vde[3] vdd[2] vdc[1] vdb[0]
      20953088 blocks super 1.2 512K chunks 2 near-copies [4/4] [UUUU]
      
unused devices: <none>

Step 3 – Create a Filesystem on the RAID Device

To be able to use the RAID device, you need to create and mount the file system on your Rocky Linux 8 | RHEL 8 system.

To create a file system for the RAID device /dev/md0 proceed as below.

mkfs.ext4 /dev/md0

Sample Output:

mke2fs 1.45.6 (20-Mar-2020)
Discarding device blocks: done                            
Creating filesystem with 5238272 4k blocks and 1310720 inodes
Filesystem UUID: e2570369-67d8-444c-9125-6afdb68dc7d5
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

Step 4 – Mount the Software RAID Device on Rocky Linux 8| RHEL 8.

Now we can mount the created partition on your preferred location.

  • Temporal Mounting

With this type of mounting, you need to mount the device each time your system is restarted. Mount it as below at /mnt

mount /dev/md0 /mnt/

Verify if the mounting is successful:

$ df -hT -P /mnt/
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/md0       ext4   20G   45M   19G   1% /mnt

We have seen that the storage has been reduced by 1/2 one of the cons of RAID 10

  • Permanent Mounting

This ensures the mounted device is persistent. We need to add the mount to the /etc/fstab file as below.

$ sudo vim /etc/fstab
/dev/md0 /mnt ext4 defaults 0 0

Now we are required to update the /etc/mdadm/mdadm.conf. This is achieved by creating a config file to describe currently active arrays.

$ mdadm --detail --scan
ARRAY /dev/md0 metadata=1.2 name=localhost.localdomain:0 UUID=089d8e15:403e261e:dbbee899:36a357b2

Make the changes to the mdadm.conf.

mdadm --detail --scan > /etc/mdadm.conf

Reboot your system to verify if the device is persistent.

sudo reboot

On successful reboot, check the device

$ df -hT -P /mnt/
Filesystem     Type  Size  Used Avail Use% Mounted on
/dev/md0       ext4   20G   45M   19G   1% /mnt

Voila!

That was pretty easy! We have triumphantly configured Software RAID on Rocky Linux 8 | RHEL 8 using mdadm. Now you can enjoy the awesomeness of the Software RAID device. I hope this was helpful.

Related posts:

Cart

Your Cart is Empty

Back To Shop