2

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?

3

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.:

$ cat /proc/mdstat 

Personalities : [raid0] [raid1] [raid10] [raid6] [raid5] [raid4] [linear] [multipath] 
md0 : active raid1 sdf2[1] sde2[0]
      81854336 blocks super 1.2 [2/2] [UU]

md127 : active raid0 sdf3[1] sde3[0]
      286718976 blocks super 1.2 512k chunks

unused devices: <none>
1

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

/dev/md0:
    0    8    18     0    active sync   /dev/sdb2
/dev/md1:
    0    8    19     0    active sync   /dev/sdb3
/dev/md2:
    0    8    20     0    active sync   /dev/sdb4
    1    8    36     1    active sync   /dev/sdc4

Note that UUID's aren't needed to track which drives are in which arrays, since the RAID superblock will handle that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.