Setting up RAID 1 on Rocky Linux is a great way to ensure that your data is safe and secure. RAID 1, also known as mirroring, creates an exact copy of your data on two or more drives, providing redundancy and increased read performance. In this article, we’ll walk you through the process of how to set up RAID 1 on Rocky Linux using mdadm
, a popular Linux software RAID utility.
Why Choose RAID 1?
RAID 1 has several benefits over other RAID configurations, such as RAID 0 and RAID 5. By mirroring your data across multiple drives, you can protect against drive failures and ensure that your data is always accessible. In addition, RAID 1 provides increased read performance, making it an ideal choice for applications that require frequent data access.
Prerequisites
Before you begin, you’ll need the following:
- A Rocky Linux system with two or more drives to be used in the RAID 1 array
- Root access to your Rocky Linux system
- Familiarity with software RAID vs. hardware RAID
How to Set Up RAID 1 on Rocky Linux
Step-1: Install mdadm
First, you’ll need to install the mdadm
package on your Rocky Linux system. This can be done using the following command:
sudo dnf install -y mdadm
For more information on installing mdadm
, visit our guide.
Step-2: Create the RAID 1 Array
Next, you’ll need to create your RAID 1 array. To do this, use the mdadm
command, specifying the drives to be included in the array. Replace /dev/sdX
and /dev/sdY
with the device names of your drives.
sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdX /dev/sdY
This will create a RAID 1 array called /dev/md0
. You can check the status of your RAID array using the following command:
sudo mdadm --detail /dev/md0
Step-3: Format the RAID Array
After creating the RAID 1 array, you’ll need to format it. In this example, we’ll use the ext4
filesystem, but you can choose a different filesystem if you prefer.
sudo mkfs.ext4 /dev/md0
Step-4: Mount the RAID Array
Now that your RAID array is formatted, you can mount it to a directory on your Rocky. Create a mount point and mount the RAID array:
sudo mkdir /mnt/raid1
sudo mount /dev/md0 /mnt/raid1
To ensure that your RAID array is mounted at boot, add the following line to /etc/fstab
:
/dev/md0 /mnt/raid1 ext4 defaults 0 0
Step-5: Configure mdadm
To ensure that your RAID 1 array is properly monitored and managed, you’ll need to update the mdadm
configuration file. First, create a new configuration file by running:
sudo mdadm --detail --scan | sudo tee /etc/mdadm.conf
This command will generate a new mdadm
configuration file based on your current RAID setup.
Next, you’ll want to ensure that the mdmonitor
service is enabled and running. This service monitors your RAID arrays and sends notifications in case of any issues. Enable and start the service using the following commands:
sudo systemctl enable mdmonitor
sudo systemctl start mdmonitor
Step-6: Test Your RAID 1 Array
With your RAID 1 array set up and configured, it’s essential to actively test its functionality to ensure everything works as expected. To simulate a drive failure, you can remove one of the drives from the RAID array using the mdadm
command:
sudo mdadm /dev/md0 --fail /dev/sdX
Replace /dev/sdX
with the device name of one of the drives in your RAID 1 array. After running this command, check the status of your RAID array:
sudo mdadm --detail /dev/md0
You should see that the drive is marked as “failed.” Despite this simulated failure, your data should still be accessible, as the RAID 1 array provides redundancy.
To repair the array, first remove the failed drive:
sudo mdadm /dev/md0 --remove /dev/sdX
Then, re-add the drive to the array:
sudo mdadm /dev/md0 --add /dev/sdX
The RAID 1 array will begin rebuilding, and you can monitor the progress using the --detail
command:
sudo mdadm --detail /dev/md0
Once the rebuilding process is complete, your RAID 1 array should be fully operational and provide redundancy and increased read performance for your data.
In conclusion, setting up a RAID 1 array on Rocky Linux using mdadm
is a relatively straightforward process that provides increased data protection and read performance. If you’re interested in exploring other RAID configurations for your Linux system, check out our guides on setting up RAID 5, RAID 6, and RAID 10.