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

Graceful array shutdown procedures

Prevent metadata corruption by ordering the shutdown of storage arrays.

In this lesson, you will learn how to sequence system stops to ensure your storage arrays remain healthy and free of metadata corruption during a power-down event.

Why Order Matters

When a Linux system shuts down, it doesn't just cut power; it signals processes and drivers to close files and flush caches. For software RAID arrays, this is a critical period. If the system stops the RAID array while the filesystem is still actively trying to write data, or if it kills the storage drivers before the array has finished flushing its internal write-intent bitmap, you risk metadata corruption. This forces an "unscheduled dirty shutdown," which often triggers a long, stressful consistency check (resync) the next time you boot up.

The Graceful Shutdown Workflow

To shut down an array safely, you must follow the dependency chain in reverse. Think of it like layers of an onion: you must peel away the upper layers before removing the core.

  1. Unmount the Filesystem: The filesystem must be completely unmounted to ensure no pending writes remain in the kernel cache.

    sudo umount /mnt/my_raid_data
    
  2. Stop the Array: Once the filesystem is clear, you must explicitly stop the RAID device. This forces the array to update its superblocks and mark the array state as "clean."

    sudo mdadm --stop /dev/md0
    
  3. Shut Down the OS: With the array stopped, the underlying physical drives can safely be powered down by the kernel without fear of leaving the RAID metadata in an inconsistent state.

Why Not Just Pull the Plug?

If you skip the --stop command, the kernel might leave the array in a "dirty" state. When the array reboots, it sees the mismatch between the expected state and the actual disk data. Even if your data is technically safe, the array will automatically perform a "check" (re-verifying parity across all disks) to ensure integrity. On a large, modern array, this process can throttle your system performance for hours. By manually stopping the array, you tell Linux: "I am done; everything is synchronized, and you don't need to check the math next time."

Key Takeaway: Always unmount your filesystems and explicitly stop your RAID devices via mdadm --stop before powering off to prevent metadata corruption and unnecessary post-boot consistency checks.