mdadm - Linux Software RAID Management
The mdadm command is a powerful utility for managing Linux software RAID arrays. It allows you to create, assemble, stop, query, and manage RAID devices, providing a flexible and robust solution for data redundancy and performance.
Creating New RAID Arrays
To initialize a new RAID array, you use the --create option. This command specifies the RAID level, the number of devices, and the devices to be included in the array, along with any spare devices.
# Example: Create a RAID 5 array with 4 devices and 1 spare
mdadm --create /dev/md${M} --level=raid5 --raid-devices=4 /dev/sd{a,b,c,d,e}${P} --spare-devices=/dev/sdf1
Assembling and Stopping RAID Arrays
Existing RAID arrays can be manually or automatically assembled. The --assemble command activates an array, while --stop deactivates it.
# Manually assemble an existing array
mdadm --assemble /dev/md${M} /dev/sd{a,b,c,d,e}${P}
# Automatically assemble all existing arrays
mdadm --assemble --scan
# Stop an assembled (active) array
mdadm --stop /dev/md${M}
Querying and Examining RAID Status
You can query the configuration of an array or examine the superblock content of individual components to understand the RAID setup and device status.
# See array configuration
mdadm --query /dev/md${M}
# See array component configuration (dump superblock content)
mdadm --query --examine /dev/sd${D}${P}
# See detailed array configuration/status
mdadm --detail /dev/md${M}
Managing RAID Components
mdadm provides commands to manage individual components of a RAID array, such as marking a device as failed, removing it, or adding a new device to replace a failed one.
# Manually mark a component as failed
mdadm --manage /dev/md${M} --fail /dev/sd${D}${P}
# Remove a failed component
mdadm --manage /dev/md${M} --remove /dev/sd${D}${P}
# Add a new component to an existing array (triggers rebuild)
mdadm --manage /dev/md${M} --add /dev/sd${D,new}${P}
Saving and Zeroing Superblocks
It's crucial to save the existing array configuration for boot-time assembly and to zero the superblock of a device before reusing it for other purposes.
# Save existing arrays configuration
mdadm --detail --scan > /etc/mdadm/mdadm.conf
# Erase array component superblock (MUST do before reusing a partition)
mdadm --zero-superblock /dev/sd${D}${P}
Additional Information
You can view the status of assembled arrays using /proc/mdstat. Renaming a device can be done during assembly with the --name and --update=name options.
# See assembled (active) arrays status
cat /proc/mdstat
# Rename a device during assembly
mdadm --assemble /dev/md${M} /dev/sd{a,b,c,d,e}${P} --name="${name}:${M}" --update=name