How to check if a RAID array is configured in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check if a RAID array is configured and healthy on a Linux system. You will use the mdadm command to get detailed information about RAID devices, verify the RAID status by inspecting the /proc/mdstat file, and examine the RAID configuration stored in /etc/mdadm.conf. These steps are crucial for monitoring and troubleshooting software RAID arrays in Linux environments.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/UserandGroupManagementGroup(["User and Group Management"]) linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/UserandGroupManagementGroup -.-> linux/sudo("Privilege Granting") subgraph Lab Skills linux/ls -.-> lab-558749{{"How to check if a RAID array is configured in Linux"}} linux/cat -.-> lab-558749{{"How to check if a RAID array is configured in Linux"}} linux/sudo -.-> lab-558749{{"How to check if a RAID array is configured in Linux"}} end

Check RAID status with mdadm --detail

In this step, you will learn how to check the status of a RAID array using the mdadm command. mdadm is a utility used to manage software RAID devices in Linux.

A RAID (Redundant Array of Independent Disks) is a way of storing the same data in different places on multiple hard disks. This can improve performance or provide redundancy, or both.

The mdadm --detail command provides detailed information about a specific RAID array.

First, let's list the available RAID devices. We can often find them in the /dev/md directory. Type the following command and press Enter:

ls /dev/md*

You might see output similar to this, indicating a RAID device named md0:

/dev/md0

Now, let's use mdadm --detail to inspect the md0 device. Type the following command and press Enter:

sudo mdadm --detail /dev/md0

You will see detailed information about the RAID array, including its status, the devices it uses, and its configuration. The output will look something like this:

/dev/md0:
        Version : 1.2
  Creation Time : ...
     Raid Level : raid1
     Array Size : ... (... GiB 1.00 TiB)
  Used Dev Size : ... (... GiB 1.00 TiB)
   Raid Devices : 2
  Total Devices : 2
    Persistence : Superblock is persistent

    Update Time : ...
          State : clean
 Active Devices : 2
Working Devices : 2
 Failed Devices : 0
  Spare Devices : 0

           Name : ...
           UUID : ...
         Events : ...

    Number   Major   Minor   RaidDevice State
       0       8       17        0      active sync   /dev/sdb1
       1       8       33        1      active sync   /dev/sdc1

Look for the State line. If it says clean and Active Devices matches Raid Devices, your RAID array is healthy.

This command is essential for monitoring the health and configuration of your software RAID arrays.

Click Continue to proceed to the next step.

Verify RAID in /proc/mdstat

In this step, you will learn another way to check the status of your software RAID arrays by examining the /proc/mdstat file.

The /proc filesystem is a virtual filesystem in Linux that provides information about processes and other system information. /proc/mdstat specifically contains the status of multiple device (md) arrays, which include software RAID.

To view the contents of this file, we can use the cat command. Type the following command in your terminal and press Enter:

cat /proc/mdstat

You will see output similar to this:

Personalities : [raid1]
md0 : active raid1 sdc1[1] sdb1[0]
      ...
      [2/2] [UU]
      bitmap: ...

unused devices: <none>

Let's break down the important parts of this output:

  • Personalities: Lists the RAID levels supported by the kernel.
  • md0: The name of the RAID device.
  • active: Indicates that the RAID array is currently active and in use.
  • raid1: The RAID level (in this case, RAID 1, which is mirroring).
  • sdc1[1] sdb1[0]: Lists the physical devices that are part of the array and their state within the array. The numbers in brackets ([1], [0]) are the device's index in the array.
  • [2/2] [UU]: This is a crucial part for checking the status.
    • [2/2]: Means 2 out of 2 expected devices are active.
    • [UU]: Represents the state of each device in the array. U means the device is "Up" or active. If you see _, it means the device is missing or failed. For a healthy RAID 1 array with two devices, you should see [UU].

Comparing the output of cat /proc/mdstat with mdadm --detail (from the previous step) can give you a quick overview and then detailed information about your RAID setup.

Click Continue to move on.

Inspect RAID config with cat /etc/mdadm.conf

In this final step, you will examine the mdadm.conf file, which is the configuration file for mdadm. This file contains information about the RAID arrays that should be assembled automatically at boot time.

While mdadm --detail and /proc/mdstat show the current status of active arrays, mdadm.conf shows the intended configuration.

To view the contents of the mdadm.conf file, use the cat command. Since this file is typically owned by the root user, you'll need to use sudo to read it. Type the following command and press Enter:

sudo cat /etc/mdadm.conf

You will see output similar to this:

## mdadm.conf
#
## Please refer to mdadm.conf(5) for information about this file.
#

## by default, scan all partitions (/proc/partitions) for MD superblocks.
## Be careful when using RAID arrays on hard drives that also contain Windows
## partitions, since Windows may destroy the superblocks.
#
SCAN /dev/disk/by-uuid/
#
## auto-create devices with Debian standard names
CREATE owner=root group=disk mode=0660 auto=yes
#
## automatically add disks in containers as appropriate
HOMEHOST <system>
## definitions of existing MD arrays
ARRAY /dev/md0 UUID=...

Key lines to notice:

  • SCAN /dev/disk/by-uuid/: This tells mdadm where to look for RAID devices when scanning the system. Using UUIDs is a reliable way to identify disks.
  • ARRAY /dev/md0 UUID=...: This line defines the RAID array /dev/md0 and associates it with a specific UUID. This allows the system to automatically assemble the array using the correct devices even if their device names (/dev/sdb1, /dev/sdc1) change.

Understanding the mdadm.conf file is important for troubleshooting RAID issues and ensuring your arrays are configured correctly for automatic assembly.

You have now learned three fundamental ways to check the status and configuration of software RAID arrays in Linux!

Click Continue to complete the lab.

Summary

In this lab, you learned how to check if a RAID array is configured in Linux using three key methods. First, you used the mdadm --detail command to get comprehensive information about a specific RAID device, including its state, level, and the devices it comprises. This command is crucial for understanding the health and configuration of your software RAID.

Next, you verified the RAID status by inspecting the /proc/mdstat file. This file provides a real-time overview of all active software RAID devices on the system, showing their status and the disks involved. Finally, you examined the /etc/mdadm.conf file to understand the persistent configuration of the RAID arrays, which is used by the system to assemble the arrays during boot. These steps provide a complete picture of how to confirm and inspect RAID configurations in a Linux environment.