Configure "Raid 1" in Linux(Mirroring)

RAID 1 - Javatpoint

Configuring RAID 1 (mirroring) on CentOS 9 involves several steps to ensure redundancy by mirroring data across two or more disks. Here's a detailed guide on how to set up RAID 1 using mdadm, which is a commonly used utility for managing software RAID in Linux.

Note: No fault tolerance occurred as we can recover the data from another disk and 50% of space will be lost.

2 disk required to implement this.

 1  init 0
    2  shutdown /i
    3  sudo yum install gnome-tweaks
    4  cat /etc/redhat-release
    5  cat /etc/centos-release
    6  cat /etc/os-release
    7  sudo yum update -y
    8  sudo yum upgrade -y
    9  sudo yum dist-upgrade -y
   10  cat /var/log/syslog
   11  ls /var/
   12  ls /var/log
   13  lsblk
   14  reboot
   15  lsblk
   16  fdisk /dev/sdb
   17  sudo fdisk /dev/sdb
   18  lsblk
   19  sudo fdisk /dev/sdc
   20  yum install mdadm -y
   21  sudo yum install mdadm -y
   22  lsblk
   23  mdadm --examine /dev/sd[b-c]1
   24  sudo mdadm --examine /dev/sd[b-c]1
   25  sudo mdadm --create /dev/md5 --level=mirror --raid-devices=2 /dev/sd[b-c]1
   26  sudo mdadm --E /dev/sd[b-c]1
   27  sudo mdadm --examine /dev/sd[b-c]1
   28  cat /proc/mdstat
   29  mdadm --detail /dev/md5
   30  sudo mdadm --detail /dev/md5
   31  mkdir /mnt/raid1
   32  sudo mkdir /mnt/raid1
   33  sudo mkfs.ext4 /dev/md5
   34  sudo blkid /dev/md5
   35  vim /etc/fstab
   36  sudo vim /etc/fstab
   37  mount -av
   38  df -h

Step-by-Step Guide to Configure RAID 1 on CentOS 9

Step 1: Install Required Packages

First, ensure that mdadm (the utility for managing RAID arrays) is installed on your CentOS system. If it's not installed, you can install it using the following command:

sudo dnf install mdadm

Step 2: Identify Disks

Identify the disks that you want to use for RAID 1. For this example, let's assume you have two disks: /dev/sda and /dev/sdb.

Step 3: Partition Disks

If your disks are new or need reconfiguration, you should partition them appropriately. You can use tools like fdisk, parted, or gdisk to create partitions on each disk. For simplicity, we'll create one partition per disk covering the entire disk space.

sudo fdisk /dev/sda
# Create a new partition (e.g., /dev/sda1) of type Linux RAID (type fd)

sudo fdisk /dev/sdb
# Create a new partition (e.g., /dev/sdb1) of type Linux RAID (type fd)

Step 4: Create RAID 1 Array

Now, let's create the RAID 1 array using mdadm:

sudo mdadm --create /dev/md0 --level=1 --raid-devices=2 /dev/sda1 /dev/sdb1
  • /dev/md0 is the name of the RAID device.

  • --level=1 specifies RAID level 1 (mirroring).

  • --raid-devices=2 specifies the number of devices in the RAID array (in this case, two disks).

  • /dev/sda1 and /dev/sdb1 are the partitions we created earlier on /dev/sda and /dev/sdb.

Step 5: Verify RAID Configuration

Check the status of the RAID array to ensure it was created successfully:

sudo mdadm --detail /dev/md0

This command provides detailed information about the RAID array md0, including its status and devices.

Step 6: Create a Filesystem

Next, create a filesystem on the RAID array. For example, to create an ext4 filesystem:

sudo mkfs.ext4 /dev/md0

Step 7: Mount the RAID Array

Create a mount point and mount the RAID array:

sudo mkdir /mnt/raid
sudo mount /dev/md0 /mnt/raid

Step 8: Configure Mount at Boot

To ensure the RAID array mounts automatically at boot time, add an entry to /etc/fstab:

echo '/dev/md0   /mnt/raid   ext4   defaults   0 0' | sudo tee -a /etc/fstab

Step 9: Test and Verify

Reboot your system to test if the RAID array mounts automatically and correctly. After rebooting, verify that the RAID array is still operational:

sudo mdadm --detail /dev/md0

Ensure that both disks (/dev/sda1 and /dev/sdb1) are active and in sync (U state).

Additional Notes:

  • Always replace /dev/sda1, /dev/sdb1, etc., with the appropriate partitions on your disks.

  • Customize RAID level (--level), RAID device name (/dev/md0), filesystem type (ext4), and mount point (/mnt/raid) as per your requirements.

  • Monitor the RAID array regularly (sudo mdadm --detail /dev/md0) to ensure both disks are functioning properly.

By following these steps, you can successfully set up RAID 1 on CentOS 9 using mdadm, providing redundancy and data protection against disk failures.