- What is RAID 1?
- Prerequisites
- Step 1: Installing mdadm
- Step 2: Identifying Drives
- Step 3: Creating the RAID 1 Array
- Step 4: Monitoring Array Creation
- Step 5: Creating a Filesystem
- Step 6: Mounting the RAID Array
- Step 7: Automating Mounting at Boot
- Step 8: Saving the RAID Configuration
- Monitoring and Maintenance
- Conclusion

Setting up a RAID 1 configuration can provide redundancy and enhance data security. Using the mdadm utility in Linux, you can create a mirrored array that ensures data preservation by duplicating it across multiple drives. This article will guide you through the steps to configure RAID 1 with mdadm, breaking down the process into easy-to-follow segments.
What is RAID 1?
RAID 1, or mirroring, is a storage technique that duplicates the same data on two or more disks. This approach offers fault tolerance—if one drive fails, the data remains accessible from the other. It’s an excellent solution for critical applications where uptime and data integrity are paramount.
Prerequisites
Before diving into the configuration, ensure that you have the following:
- At least two hard drives (or SSDs) of equal size.
- A Linux distribution with
mdadminstalled. You can install it using your package manager, such asaptfor Debian-based systems oryumfor Red Hat-based systems. - Sufficient permissions (root access) to perform disk operations.
Step 1: Installing mdadm
If mdadm is not already installed on your system, you can do so using the following commands:
For Debian-based systems:
sudo apt update
sudo apt install mdadm
For Red Hat-based systems:
sudo yum install mdadm
Step 2: Identifying Drives
Next, identify the drives you wish to use for the RAID 1 configuration. You can list all connected drives using:
lsblk
Alternatively, you can use:
fdisk -l
Select the drives intended for the RAID array (e.g., /dev/sdb and /dev/sdc). Ensure these drives do not contain any important data, as the following steps will format them.
Step 3: Creating the RAID 1 Array
To create the RAID 1 array, use the mdadm command as follows:
sudo mdadm --create --verbose /dev/md0 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
In this command:
/dev/md0is the name of the RAID array you are creating.--level=1specifies RAID 1.--raid-devices=2indicates that there will be two disks in this array.
Step 4: Monitoring Array Creation
The creation process may take some time, particularly for larger drives. You can monitor the status using:
cat /proc/mdstat
This command shows the progress of the RAID array creation, including the synchronization status.
Step 5: Creating a Filesystem
Once the array is created, you’ll need to create a filesystem on it. Use the mkfs command:
sudo mkfs.ext4 /dev/md0
This will format the RAID device with the EXT4 filesystem. You can substitute ext4 with another filesystem type if desired.
Step 6: Mounting the RAID Array
After formatting, you need to create a mount point and mount the RAID array:
sudo mkdir -p /mnt/raid1
sudo mount /dev/md0 /mnt/raid1
To verify that it’s mounted correctly, check:
df -h
Step 7: Automating Mounting at Boot
To ensure that the RAID array mounts automatically at system startup, you need to add an entry to your /etc/fstab. Open the file as a superuser:
sudo nano /etc/fstab
Add the following line to the end of the file:
/dev/md0 /mnt/raid1 ext4 defaults 0 0
Step 8: Saving the RAID Configuration
To save your RAID configuration, so it can be reassembled after a reboot, use the following command:
sudo mdadm --detail --scan | sudo tee -a /etc/mdadm/mdadm.conf
Then, update the initramfs:
sudo update-initramfs -u
Monitoring and Maintenance
To ensure your RAID 1 array is functioning correctly, regularly check its status with:
sudo mdadm --detail /dev/md0
Conclusion
Configuring RAID 1 with mdadm is a straightforward process that can significantly enhance data resilience. By following these steps, you can set up a mirrored storage solution that ensures your critical data is safe and available, even in the event of a disk failure. Regular monitoring and maintenance will help you keep the RAID array in optimal condition, providing peace of mind in your data management strategy.