Understanding RAID
RAID, originally standing for Redundant Arrays of Inexpensive Disks and now commonly referred to as Redundant Arrays of Independent Disks, is a technology designed to combine multiple physical storage drives into a single logical unit. The primary goals are:
- Performance Enhancement: Increasing read/write speeds through parallel disk operations.
- Reliability: Providing data redundancy to protect against hardware failure.
Note: RAID is not a substitute for a backup strategy. It protects against hardware failure but cannot recover data deleted by user error or corrupted by software issues.
Common RAID Levels
RAID levels define how data is distributed across the drives. Here are the most common configurations:
- RAID 0 (Striping): Data is split across all disks. Offers excellent speed but zero redundancy. If one drive fails, all data is lost.
Minimum Disks: 2 | Capacity: 100% of total disks. - RAID 1 (Mirroring): Data is duplicated identically to two or more disks. Read performance is good; write performance may decrease slightly.
Minimum Disks: 2 | Capacity: 50% of total disks (size of the smallest disk). - RAID 4: Uses a dedicated parity disk. If a data disk fails, the parity disk is used to reconstruct data. The dedicated parity disk can be a bottleneck.
Minimum Disks: 3 | Capacity: (N-1) * size. - RAID 5 (Distributed Parity): Similar to RAID 4, but parity information is rotated across all disks instead of being stored on a single dedicated drive. This alleviates the bottleneck found in RAID 4.
Minimum Disks: 3 | Capacity: (N-1) * size | Fault Tolerance: 1 disk. - RAID 6 (Double Parity): Extends RAID 5 by adding a second parity block, allowing the array to survive the failure of two disks simultaneously.
Minimum Disks: 4 | Capacity: (N-2) * size | Fault Tolerance: 2 disks. - RAID 10 (Stripe of Mirrors): Data is mirrored first, then striped. Offers the speed of RAID 0 and the safety of RAID 1.
Minimum Disks: 4 | Capacity: 50% of total disks. - JBOD (Just a Bunch Of Disks): Not technically RAID, this simply concatenates disks to appear as one large volume.
Capacity: Sum of all disks.
Software RAID Management with mdadm
Linux implements software RAID using the mdadm utility. It supports creating, managing, and monitoring arrays (Linear, RAID 0, 1, 4, 5, 6, 10).
Key Command Options
-C: Create mode.-l #: Specifies the RAID level (e.g., 5).-n #: Number of active devices in the array.-x #: Number of hot spare disks.-a yes: Automatically create the device file.-c: Set chunk size.-D: Display detailed array information.-f: Mark a disk as faulty.-r: Remove a disk from the array.-S: Stop the array.
Monitoring
To check the status of the arrays in real-time, view the /proc/mdstat file:
cat /proc/mdstat
You can use watch to refresh the status automatically:
watch -n 1 cat /proc/mdstat
Practical Example: Creating a 1GB RAID 5 Array
This example demonstrates creating a RAID 5 array with 4 active drives and 1 hot spare using loop devices or partitions (assuming parittions like /dev/sdb1 through /dev/sdb5 exist and are of type fd).
1. Create the array using mdadm:
mdadm -C /dev/md1 -a yes -l 5 -n 4 -x 1 /dev/sdb{1,2,3,4,5}
2. Verify the array creation and check the rebuild status:
mdadm -D /dev/md1
3. Format the new RAID device with a filesystem (e.g., ext4):
mkfs.ext4 /dev/md1
4. Mount the volume to a directory:
mkdir -p /data/storage
mount /dev/md1 /data/storage
5. Check the available space:
df -h /data/storage
Simulating Failure and Recovery
1. Mark a disk as failed (simulating a hardware crash):
mdadm /dev/md1 -f /dev/sdb1
At this point, the hot spare should automatically activate and start rebuilding. Data remains accessible.
2. Remove the failed disk from the array:
mdadm /dev/md1 -r /dev/sdb1
3. Add a new replacement disk to the array:
mdadm /dev/md1 -a /dev/sdb6