How to check RAID details → mdadm --detail /dev/md0
How to Check RAID Details → mdadm --detail /dev/md0
Table of Contents
1. [Introduction](#introduction)
2. [Prerequisites](#prerequisites)
3. [Understanding mdadm and RAID Arrays](#understanding-mdadm-and-raid-arrays)
4. [Basic mdadm --detail Command Usage](#basic-mdadm---detail-command-usage)
5. [Understanding the Output](#understanding-the-output)
6. [Practical Examples](#practical-examples)
7. [Advanced Usage and Options](#advanced-usage-and-options)
8. [Common Issues and Troubleshooting](#common-issues-and-troubleshooting)
9. [Best Practices](#best-practices)
10. [Related Commands](#related-commands)
11. [Conclusion](#conclusion)
Introduction
The `mdadm --detail` command is an essential tool for Linux system administrators and users working with software RAID arrays. This comprehensive guide will teach you how to effectively use the `mdadm --detail /dev/md0` command to examine RAID array configurations, monitor disk health, and troubleshoot potential issues.
RAID (Redundant Array of Independent Disks) arrays provide data redundancy, improved performance, or both by combining multiple physical drives into logical units. The mdadm utility is the standard tool for managing software RAID arrays in Linux systems, and the `--detail` option provides crucial information about array status, member drives, and configuration parameters.
By the end of this guide, you'll understand how to interpret RAID array details, identify potential problems, and make informed decisions about your storage infrastructure.
Prerequisites
Before diving into the `mdadm --detail` command, ensure you have:
System Requirements
- A Linux system with mdadm installed
- Root or sudo privileges
- An existing software RAID array (we'll use `/dev/md0` as an example)
- Basic understanding of Linux command line
Installing mdadm
If mdadm isn't installed on your system, install it using your distribution's package manager:
Ubuntu/Debian:
```bash
sudo apt update
sudo apt install mdadm
```
CentOS/RHEL/Fedora:
```bash
sudo yum install mdadm # CentOS/RHEL 7
sudo dnf install mdadm # Fedora/RHEL 8+
```
Verifying RAID Arrays
To list existing RAID arrays on your system:
```bash
cat /proc/mdstat
```
This command shows active RAID arrays and their current status.
Understanding mdadm and RAID Arrays
What is mdadm?
mdadm (multiple device admin) is a Linux utility used to manage and monitor software RAID devices. It can create, assemble, report on, and control RAID arrays using the md (multiple device) driver.
Common RAID Levels
- RAID 0: Striping for performance (no redundancy)
- RAID 1: Mirroring for redundancy
- RAID 5: Striping with distributed parity
- RAID 6: Striping with double distributed parity
- RAID 10: Combination of RAID 1 and RAID 0
The md Device
Software RAID arrays in Linux are represented as `/dev/mdX` devices, where X is a number (0, 1, 2, etc.). These are virtual block devices that present the combined storage of multiple physical drives as a single logical unit.
Basic mdadm --detail Command Usage
Command Syntax
The basic syntax for checking RAID details is:
```bash
mdadm --detail /dev/mdX
```
Where `X` is the RAID array number.
Basic Example
To check details of the first RAID array:
```bash
sudo mdadm --detail /dev/md0
```
Alternative Syntax
You can also use the short form:
```bash
sudo mdadm -D /dev/md0
```
The `-D` flag is equivalent to `--detail`.
Understanding the Output
When you run `mdadm --detail /dev/md0`, you'll see output similar to this:
```
/dev/md0:
Version : 1.2
Creation Time : Wed Oct 15 10:30:25 2023
Raid Level : raid1
Array Size : 976630336 (930.86 GiB 999.65 GB)
Used Dev Size : 976630336 (930.86 GiB 999.65 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Nov 16 14:22:10 2023
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Name : server01:0 (local to host server01)
UUID : 12345678:abcdefgh:ijklmnop:qrstuvwx
Events : 1847
Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 8 17 1 active sync /dev/sdb1
```
Let's break down each section:
Header Information
- Version: Metadata version used by the array
- Creation Time: When the array was originally created
- Raid Level: The RAID configuration (raid0, raid1, raid5, etc.)
Size Information
- Array Size: Total usable space of the array
- Used Dev Size: Space used on each device
- Raid Devices: Number of devices that make up the RAID
- Total Devices: Total number of devices (including spares)
Status Information
- State: Current array state (clean, degraded, failed, etc.)
- Active Devices: Number of working devices
- Working Devices: Devices that are functional
- Failed Devices: Number of failed devices
- Spare Devices: Number of hot spare devices
Identification
- Name: Array name (usually hostname:number)
- UUID: Unique identifier for the array
- Events: Number of events (writes, failures, etc.)
Device List
The bottom section shows each device with:
- Number: Device number in the array
- Major/Minor: Device major and minor numbers
- RaidDevice: Position in the RAID array
- State: Device state (active sync, spare, faulty, etc.)
- Device Path: Physical device path
Practical Examples
Example 1: Healthy RAID 1 Array
```bash
sudo mdadm --detail /dev/md0
```
Output for a healthy RAID 1 array:
```
/dev/md0:
Version : 1.2
Creation Time : Mon Jan 15 09:15:30 2024
Raid Level : raid1
Array Size : 1953382464 (1862.89 GiB 2000.26 GB)
Used Dev Size : 1953382464 (1862.89 GiB 2000.26 GB)
Raid Devices : 2
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Jan 18 16:45:22 2024
State : clean
Active Devices : 2
Working Devices : 2
Failed Devices : 0
Spare Devices : 0
Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 8 17 1 active sync /dev/sdb1
```
Analysis: This shows a healthy RAID 1 array with both devices active and synchronized.
Example 2: Degraded RAID Array
```bash
sudo mdadm --detail /dev/md1
```
Output for a degraded array:
```
/dev/md1:
Version : 1.2
Creation Time : Mon Jan 15 09:20:45 2024
Raid Level : raid5
Array Size : 2930277376 (2794.16 GiB 3000.46 GB)
Used Dev Size : 1465138688 (1397.08 GiB 1500.23 GB)
Raid Devices : 3
Total Devices : 2
Persistence : Superblock is persistent
Update Time : Thu Jan 18 17:22:15 2024
State : clean, degraded
Active Devices : 2
Working Devices : 2
Failed Devices : 1
Spare Devices : 0
Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 0 0 1 removed
2 8 33 2 active sync /dev/sdc1
```
Analysis: This RAID 5 array is degraded because one device has failed and been removed.
Example 3: RAID Array with Hot Spare
```bash
sudo mdadm --detail /dev/md2
```
Output showing a hot spare:
```
/dev/md2:
Version : 1.2
Creation Time : Tue Jan 16 11:30:00 2024
Raid Level : raid6
Array Size : 3906777088 (3725.78 GiB 4000.65 GB)
Used Dev Size : 1953388544 (1862.89 GiB 2000.33 GB)
Raid Devices : 4
Total Devices : 5
Persistence : Superblock is persistent
Update Time : Thu Jan 18 18:10:33 2024
State : clean
Active Devices : 4
Working Devices : 5
Failed Devices : 0
Spare Devices : 1
Number Major Minor RaidDevice State
0 8 1 0 active sync /dev/sda1
1 8 17 1 active sync /dev/sdb1
2 8 33 2 active sync /dev/sdc1
3 8 49 3 active sync /dev/sdd1
4 8 65 - spare /dev/sde1
```
Analysis: This RAID 6 array has four active devices and one hot spare ready to take over if a device fails.
Advanced Usage and Options
Verbose Output
For more detailed information, use the verbose flag:
```bash
sudo mdadm --detail --verbose /dev/md0
```
This provides additional technical details about the array configuration.
Brief Output
For a condensed view:
```bash
sudo mdadm --detail --brief /dev/md0
```
This shows only essential information in a single line format.
Export Format
To get output suitable for configuration files:
```bash
sudo mdadm --detail --brief --verbose /dev/md0
```
Checking Multiple Arrays
To check all arrays at once:
```bash
for array in /dev/md*; do
if [ -b "$array" ]; then
echo "=== $array ==="
sudo mdadm --detail "$array"
echo
fi
done
```
Monitoring Script Example
Create a simple monitoring script:
```bash
#!/bin/bash
raid_check.sh
ARRAYS=$(cat /proc/mdstat | grep "^md" | awk '{print "/dev/"$1}')
for array in $ARRAYS; do
echo "Checking $array..."
STATE=$(mdadm --detail $array | grep "State :" | awk '{print $3}')
if [ "$STATE" != "clean" ]; then
echo "WARNING: $array is in state: $STATE"
mdadm --detail $array
else
echo "$array is healthy"
fi
echo "---"
done
```
Common Issues and Troubleshooting
Issue 1: "mdadm: cannot open /dev/md0: No such file or directory"
Cause: The RAID array doesn't exist or isn't assembled.
Solutions:
1. Check if the array exists:
```bash
cat /proc/mdstat
```
2. List available arrays:
```bash
sudo mdadm --examine --scan
```
3. Assemble the array if it exists:
```bash
sudo mdadm --assemble /dev/md0
```
Issue 2: "mdadm: md0 stopped"
Cause: The array has been stopped or failed.
Solutions:
1. Try to restart the array:
```bash
sudo mdadm --assemble /dev/md0
```
2. Check for component devices:
```bash
sudo mdadm --examine /dev/sda1 /dev/sdb1
```
3. Force assembly if necessary:
```bash
sudo mdadm --assemble --force /dev/md0 /dev/sda1 /dev/sdb1
```
Issue 3: Array Shows as "Degraded"
Cause: One or more drives have failed or been removed.
Solutions:
1. Identify the failed device:
```bash
sudo mdadm --detail /dev/md0
```
2. Remove the failed device:
```bash
sudo mdadm --manage /dev/md0 --remove /dev/sdX1
```
3. Add a replacement device:
```bash
sudo mdadm --manage /dev/md0 --add /dev/sdY1
```
Issue 4: "Permission Denied" Error
Cause: Insufficient privileges to access the device.
Solution:
Always use `sudo` when running mdadm commands:
```bash
sudo mdadm --detail /dev/md0
```
Issue 5: Array in "Resync" State
Cause: The array is rebuilding or synchronizing data.
What to do:
1. Check progress:
```bash
cat /proc/mdstat
```
2. Monitor the process:
```bash
watch cat /proc/mdstat
```
3. Be patient - resync can take hours depending on array size.
Best Practices
Regular Monitoring
1. Schedule regular checks: Set up cron jobs to check array status daily:
```bash
# Add to crontab
0 6 * /usr/sbin/mdadm --detail /dev/md0 | grep -q "State : clean" || echo "RAID issue detected" | mail -s "RAID Alert" admin@example.com
```
2. Monitor /proc/mdstat: Regularly check this file for array status:
```bash
cat /proc/mdstat
```
Documentation
1. Record array configurations: Save array details for reference:
```bash
sudo mdadm --detail --brief /dev/md0 >> /etc/mdadm/mdadm.conf
```
2. Keep device serial numbers: Document which physical drives correspond to which array positions.
Maintenance
1. Test regularly: Perform regular RAID consistency checks:
```bash
echo check > /sys/block/md0/md/sync_action
```
2. Monitor drive health: Use tools like `smartctl` to monitor individual drive health:
```bash
sudo smartctl -a /dev/sda
```
Performance Optimization
1. Check alignment: Ensure proper partition alignment for optimal performance.
2. Monitor performance: Use `iostat` to monitor array performance:
```bash
iostat -x 1
```
Backup Strategy
1. Don't rely solely on RAID: RAID is not a backup solution.
2. Regular backups: Implement comprehensive backup strategies.
3. Test recovery procedures: Regularly test your ability to recover from failures.
Related Commands
Essential mdadm Commands
```bash
Show all RAID arrays
cat /proc/mdstat
Examine a device for RAID metadata
sudo mdadm --examine /dev/sda1
Monitor RAID arrays
sudo mdadm --monitor --daemonise --mail=admin@example.com /dev/md0
Stop an array
sudo mdadm --stop /dev/md0
Assemble an array
sudo mdadm --assemble /dev/md0
Add a device to an array
sudo mdadm --manage /dev/md0 --add /dev/sdc1
Remove a device from an array
sudo mdadm --manage /dev/md0 --remove /dev/sdc1
Mark a device as failed
sudo mdadm --manage /dev/md0 --fail /dev/sdc1
```
System Information Commands
```bash
List block devices
lsblk
Show disk usage
df -h
Show detailed disk information
sudo fdisk -l
Check filesystem
sudo fsck /dev/md0
Monitor I/O statistics
iostat -x 1 5
```
Conclusion
The `mdadm --detail` command is an indispensable tool for managing and monitoring software RAID arrays in Linux environments. Understanding how to interpret its output enables you to:
- Monitor array health: Quickly identify degraded or failed arrays
- Plan maintenance: Understand when drives need replacement
- Troubleshoot issues: Diagnose problems with array configuration or performance
- Document configurations: Keep accurate records of your storage infrastructure
Key Takeaways
1. Regular monitoring is crucial: Use `mdadm --detail` as part of your regular system maintenance routine
2. Understand the output: Each piece of information provides valuable insights into array health and performance
3. Act on warnings: Don't ignore degraded states or failed devices
4. Maintain documentation: Keep records of array configurations and device serial numbers
5. Combine with other tools: Use alongside monitoring tools and backup solutions
Next Steps
After mastering the `mdadm --detail` command, consider:
1. Setting up monitoring: Implement automated RAID monitoring with email alerts
2. Learning recovery procedures: Practice recovering from simulated failures
3. Exploring advanced features: Learn about RAID level migration and array expansion
4. Implementing comprehensive monitoring: Use tools like Nagios, Zabbix, or Prometheus for enterprise monitoring
Remember that RAID provides redundancy and performance benefits, but it's not a substitute for proper backup procedures. Always maintain regular backups of critical data and test your recovery procedures regularly.
By following the practices and techniques outlined in this guide, you'll be well-equipped to manage and monitor your Linux software RAID arrays effectively, ensuring optimal performance and data protection for your systems.