RAID 1 (Mirroring) is a storage configuration that duplicates data across two or more disks. This provides high redundancy, as an identical copy of the data is stored on each disk in the array. If one disk fails, the data remains accessible on the other disk(s), ensuring continuous operation without data loss. RAID 1 is primarily used for critical applications where data safety is paramount.
- Data Mirroring: All data written to one disk is simultaneously written to another disk.
- Fault Tolerance: Provides high availability by allowing the system to continue running even if a disk fails.
- Performance: Read performance is enhanced since data can be read from any disk in the array, but write performance is generally the same as a single disk due to mirroring.
Use Case: RAID 1 is ideal for systems where data integrity and uptime are crucial, such as file servers, database servers, and high-availability systems.
- First, ensure that mdadm is installed on your Debian system:
sudo apt update
sudo apt install mdadm
- To create a RAID 1 array with two disks (assuming /dev/sdb and /dev/sdc):
sudo mdadm --create --verbose /dev/md1 --level=1 --raid-devices=2 /dev/sdb /dev/sdc
- /dev/md1: Name of the RAID device.
- --level=1: Specifies RAID 1 (mirroring).
- --raid-devices=2: Indicates the number of devices in the RAID array.
- /dev/sdb, /dev/sdc: The two disks to use for the RAID array.
sudo cat /proc/mdstat
- Once the RAID array is created, save the configuration to /etc/mdadm/mdadm.conf:
sudo mdadm --detail --scan /dev/md1 >> /etc/mdadm/mdadm.conf
- Update the initramfs to include the RAID configuration:
sudo update-initramfs -u
- Next, format the RAID device (/dev/md1) with a filesystem:
sudo mkfs.ext4 /dev/md1
- You can replace ext4 with another filesystem if needed (e.g., xfs, btrfs).
- Create a mount point for the RAID array:
sudo mkdir /mnt/raid_1
- Now, mount the RAID array:
sudo mount /dev/md1 /mnt/raid_1/
- Create a test file to verify that the array is working properly:
echo "This is a test file for RAID 1" | sudo tee /mnt/raid_1/testfile.txt
- Verify the file:
ls /mnt/raid_1
cat /mnt/raid_1/testfile.txt
- To check the RAID array's status, use:
sudo mdadm --detail /dev/md1
- This will provide detailed information about the array, including the status of the devices and the array itself.
- To simulate a disk failure, fail one of the disks in the array:
sudo mdadm --manage /dev/md1 --fail /dev/sdb
- Check the array status:
sudo mdadm --detail /dev/md1
- The failed disk (/dev/sdb) will be marked as "failed" or "removed," but the array should still function.
- Despite the disk failure, the data remains mirrored on the other disk. Verify the test file is still accessible:
cat /mnt/raid_1/testfile.txt
- To reassemble the RAID array:
- Stop the RAID array:
sudo mdadm --stop /dev/md1
- Reassemble the RAID array:
sudo mdadm --assemble /dev/md1
- Check the RAID array status:
sudo mdadm --detail /dev/md1
- To add a new disk (/dev/sdd) to the RAID 1 array and rebuild it:
- Add the new disk to the array:
sudo mdadm --add /dev/md1 /dev/sdd
- Monitor the rebuild process:
sudo cat /proc/mdstat
- After the rebuild completes, verify the RAID status:
sudo mdadm --detail /dev/md1
- Verify that the test file is still intact after adding the new disk and rebuilding the array:
cat /mnt/raid_1/testfile.txt
- The file should still be accessible, confirming that the RAID array is functioning properly and that the data is mirrored across all disks.
- If changes were made to the RAID array (e.g., adding new disks), update the mdadm.conf file:
sudo mdadm --detail --scan /dev/md1 >> /etc/mdadm/mdadm.conf
- Then, update the initramfs again to ensure changes persist across reboots:
sudo update-initramfs -u
You now have a fully functional RAID 1 array on Debian, complete with steps for creating the array, verifying data, and simulating disk failure and rebuild. This implementation ensures our RAID 1 setup is working as expected, with data mirrored across disks. By adding and rebuilding disks, we can effectively recover from disk failure and maintain data redundancy.
๐จโ๐ป ๐๐ป๐ช๐ฏ๐ฝ๐ฎ๐ญ ๐ซ๐: Suraj Kumar Choudhary | ๐ฉ ๐๐ฎ๐ฎ๐ต ๐ฏ๐ป๐ฎ๐ฎ ๐ฝ๐ธ ๐๐ ๐ฏ๐ธ๐ป ๐ช๐ท๐ ๐ฑ๐ฎ๐ต๐น: [email protected]