I have a linux software RAID using md. I want to list all of my RAID arrays and each hard drive attached to them. Is there an easy way to do that?
I have a linux software RAID using md. I want to list all of my RAID arrays and each hard drive attached to them. Is there an easy way to do that?
cat /proc/mdstat
will give you the output you need, relatively easy to parse, because the mapped device is on the same line as its members, e.g.:Method #1 - using mdadm's details
You can use the
mdadm
commands verbose switch,-v
, to get the list of devices from the--detail --scan
switches output in a form that's pretty easy to parse into a comma separated form.This can be further refined into 1 per line.
Things can of course be shortened up with the short switches to
mdadm
.Method #2 - using mdadm's query
You can use the query (
-Q
) & details (-D
) along with verbos (-v
) to do something similar:Method #3 - using /proc/mdstat
You can also parse the list of HDD members from the
/proc/mdstat
output like so:These will be missing the
/dev
portion but you can easily add that in manually like so:If you have three software RAID arrays attached to the system (md0, md1, md2), the following simple one-liner will display the drives attached to each (change the ..2 to your total number of arrays):
sudo mdadm --query --detail /dev/md{0..2} | grep dev
Note that UUID's aren't needed to track which drives are in which arrays, since the RAID superblock will handle that.