Configuring RAID Arrays
1. Understanding RAID Levels
| RAID Level | Description | Redundancy | Performance |
|---|---|---|---|
| RAID 0 | Striping without parity. Data is split across multiple disks. | None | High read/write |
| RAID 1 | Mirroring. Data is duplicated on two or more disks. | Full | Low read, high write |
| RAID 5 | Striping with distributed parity. Requires at least 3 disks. | One disk | Medium read, medium write |
| RAID 6 | Striping with dual distributed parity. Requires at least 4 disks. | Two disks | Medium read, medium write |
| RAID 10 | Combination of mirroring and striping. Requires at least 4 disks. | Full | High read, high write |
Note: RAID 0 offers no redundancy and is not recommended for critical data.
Warning: RAID levels with parity (5, 6) can be slow during rebuilds.
2. Creating RAID with mdadm
Example: Create a RAID 1 Array
sudo mdadm --create /dev/md0 \
--level=1 \
--raid-devices=2 \
/dev/sdb1 \
/dev/sdc1
| Option | Values | Description |
|---|---|---|
| --create | /dev/md0 |
Device name for the RAID array |
| --level | 0, 1, 5, 6, 10 |
RAID level to use |
| --raid-devices | 2 |
Number of devices in the array |
| --name | myarray |
Name for the array (optional) |
Note: Ensure disks are unmounted and have no existing filesystems before creating the array.
Warning: Incorrect RAID configuration can lead to data loss. Always backup critical data before proceeding.
RAID Level Summary
- 0: Striped array, no redundancy
- 1: Mirrored array, high redundancy
- 5: Distributed parity, good read performance
- 6: Distributed dual parity, better fault tolerance
- 10: Striped mirrors, best performance and redundancy
3. Viewing RAID Status
| Property | Description | Notes |
|---|---|---|
| State | Current state of the array (active, degraded, etc.) | Shows if array is healthy or has issues |
| Devices | Number of devices in the array | Shows total and active devices |
| Array Size | Total size of the RAID array | Sum of all device sizes |
| Used Dev Size | Size of each individual device | Shows size of each member disk |
| UUID | Unique identifier for the array | Used to identify and manage arrays |
Note: The
mdadm --detail command provides detailed information about the RAID array's configuration and status.4. Adding Disks to RAID
| Step | Action | Description |
|---|---|---|
| 1 | mdadm --manage /dev/mdX --add /dev/sdY |
Add a new disk to an existing RAID array. Replace mdX with the array device and sdY with the new disk. |
| 2 | watch -n 1 cat /proc/mdstat |
Monitor the rebuild process to ensure the disk is being added and data is syncing. |
| 3 | mdadm --detail /dev/mdX |
Verify the status of the RAID array to confirm the new disk is active and rebuilding. |
Example: Adding a Disk to RAID 1 Array
# Add a new disk to an existing RAID 1 array
mdadm --manage /dev/md0 --add /dev/sdb
# Monitor the rebuild process
watch -n 1 cat /proc/mdstat
Note: Ensure the new disk is of equal or greater size than the existing disks in the array to maintain redundancy.
5. Removing Failed Disks
| Step | Action | Description |
|---|---|---|
| 1 | mdadm --manage /dev/mdX --remove /dev/sdY |
Remove a failed disk from the array. Replace /dev/mdX with the array device and /dev/sdY with the failed disk. |
| 2 | mdadm --manage /dev/mdX --add /dev/sdZ |
Add a new disk to replace the failed one. Ensure /dev/sdZ is a healthy disk. |
| 3 | cat /proc/mdstat |
Verify the array rebuild process has started and is progressing. |
Example: Removing and Replacing a Disk
# Check current array status
mdadm --detail /dev/md0
# Remove failed disk
mdadm --manage /dev/md0 --remove /dev/sdb
# Add new disk to array
mdadm --manage /dev/md0 --add /dev/sdc
# Monitor rebuild progress
watch cat /proc/mdstat
Note: Ensure the new disk is of equal or greater size than the failed one to maintain array integrity.
Warning: Removing a disk from an array that is not marked as failed can lead to data loss. Always confirm the disk status before removal.
6. Stopping RAID Arrays
Example: Stopping a RAID Array
# Stop the RAID array
mdadm --stop /dev/md0
# Or stop all active arrays
mdadm --stop --scan
| Command | Description | Notes |
|---|---|---|
| mdadm --stop <array> | Stops a specific RAID array | Array must be inactive before stopping |
| mdadm --stop --scan | Stops all currently active RAID arrays | Useful for cleanup before system shutdown |
Note: Ensure all data is safely written to disk before stopping arrays to prevent data loss.
Warning: Stopping a RAID array while it's in use can cause data corruption or loss. Always verify that no processes are using the array before stopping it.
7. Assembling RAID Arrays
| Option | Values | Description |
|---|---|---|
| --assemble | --assemble |
Assemble a RAID array from existing devices |
| --scan | --scan |
Scan for and assemble all arrays defined in configuration |
| --force | --force |
Force assembly even if devices are not clean |
Note: Ensure that the array configuration matches the devices being assembled to avoid data corruption.
Warning: Using
--force can lead to data loss if the array is not properly aligned or has inconsistencies.
Assembling Process Summary
- Identify the RAID devices and their configuration.
- Use
mdadm --assembleto reconstruct the array from its component disks. - Verify that the array is correctly assembled and healthy.
8. Saving RAID Configuration
Example: Save RAID configuration using mdadm
# Save RAID configuration to /etc/mdadm/mdadm.conf
mdadm --detail --scan > /etc/mdadm/mdadm.conf
# Verify the configuration file
cat /etc/mdadm/mdadm.conf
| Command | Description | Notes |
|---|---|---|
| mdadm --detail --scan | Scans all RAID devices and generates configuration entries | Used to create the mdadm.conf file |
| mdadm --examine | Examines a RAID device for metadata and configuration details | Helps in identifying devices and their status |
Note: The
/etc/mdadm/mdadm.conf file should be backed up to ensure that RAID arrays can be properly reassembled after a system reboot.Warning: Ensure that the
/etc/mdadm/mdadm.conf file is correctly updated after any changes to the RAID array configuration to avoid data loss or misconfiguration.9. Monitoring RAID Health
| Property | Description | Notes |
|---|---|---|
| State | Current state of the array (active, degraded, failed) | Indicates overall health status |
| Devices | Number of devices in the array | Should match expected count |
| Active Devices | Number of active devices | Should match expected count |
| Failed Devices | Number of failed devices | Should be zero for healthy arrays |
| Spare Devices | Number of spare devices available | Can be used to replace failed drives |
Note: Use
journalctl to check for RAID-related events or errors in systemd logs.| Field | Description | Interpretation |
|---|---|---|
| md0 | RAID array name | Array is active and running |
| [UU] | Device status (U = up) | All devices are healthy |
| [UUU] | Device status (U = up) | All devices are healthy |
10. Growing RAID Arrays
Example: Adding a new drive to an existing RAID 5 array
# Check current array status
mdadm --detail /dev/md0
# Add new drive to the array
mdadm --add /dev/md0 /dev/sdc
# Monitor rebuild progress
watch -n 1 cat /proc/mdstat
| Command | Description | Notes |
|---|---|---|
| mdadm --add <array> <device> | Adds a new drive to an existing array | Drive must be same size or larger than existing drives |
| mdadm --grow <array> --raid-devices=<count> | Changes the number of devices in an array | Can be used to expand RAID 5 or 6 arrays |
| mdadm --grow <array> --size=<size> | Changes the size of an array | Use with caution, may cause data loss if not properly aligned |
Note: Growing a RAID array requires sufficient space on the new drive to accommodate the expanded array size. Ensure that all drives in the array are healthy before attempting to grow.
Warning: Expanding a RAID array can be risky and may lead to data loss if not done correctly. Always backup your data before performing any array expansion operations.