Course contentsShow
← Linux
Lesson 702 of 1,8197. Storage Management and Logical VolumesFree lesson

Managing RAID state through udev

Understand how assembly events are triggered upon kernel discovery of RAID members.

In this lesson, you will learn how the Linux kernel uses udev to automatically detect and assemble RAID arrays as soon as the hardware is initialized.

When you boot your system or plug in a drive, the kernel discovers the physical storage devices. If a partition or disk contains a RAID superblock, the kernel doesn't just sit there—it needs a way to signal that a "member" of a potential RAID array has arrived. This is where udev enters the picture.

The Role of Udev Rules

udev is the device manager for the Linux kernel. It monitors for device events (like add or change). When a disk is detected, udev processes a set of predefined rules located in /lib/udev/rules.d/. Specifically, software RAID (mdadm) relies on these rules to trigger the mdadm --incremental (or mdadm -I) command.

Think of it like a receptionist at an office. When a new person walks through the door (the drive is detected), the receptionist (udev) checks their ID badge (the RAID superblock). If the badge identifies them as part of a specific project team (the RAID array), the receptionist immediately calls the project manager (mdadm) to welcome them into the fold.

How Assembly is Triggered

When a drive is detected, a udev rule typically executes a command similar to this:

# Example of a udev trigger for RAID member assembly
ACTION=="add|change", KERNEL=="sd*[0-9]", IMPORT{program}="/sbin/mdadm --examine --export $devnode", ENV{MD_DEVICE}=="yes", RUN+="/sbin/mdadm --incremental $devnode"

In this snippet:

  1. ACTION=="add|change": The rule watches for drives being added or modified.
  2. --examine: It checks if the device has a valid RAID superblock.
  3. ENV{MD_DEVICE}=="yes": If the scan confirms it's a RAID member, the rule proceeds.
  4. RUN+=...: Finally, it executes the incremental assembly. This allows the array to start up automatically without you having to manually run a command every time the system boots.

This automation is critical; it ensures that your RAID array is assembled as early as possible in the boot process, allowing the kernel to mount filesystems stored on the array without manual intervention.

Key Takeaway: Udev acts as the bridge between kernel hardware discovery and the mdadm utility, automatically triggering incremental assembly to ensure RAID arrays are ready for use the moment their member drives are detected.