问题原文
原帖链接 · fatal_error · CC BY-SA 3.0
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?
已采纳解答
原帖链接 · slm · CC BY-SA 4.0
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.
$ mdadm -v --detail --scan /dev/md/raid1 | awk -F= '/^[ ]+devices/ {print $2}'
/dev/sda1,/dev/sdb1,/dev/sdc1,/dev/sde1
This can be further refined into 1 per line.
$ mdadm -v --detail --scan /dev/md/raid1 | awk -F= '/^[ ]+devices/ {print $2}' | tr , '\n'
/dev/sda1
/dev/sdb1
/dev/sdc1
/dev/sde1
Things can of course be shortened up with the short switches to mdadm.
$ mdadm -vDs /dev/md/raid1 | awk -F= '/^[ ]+devices/ {print $2}' | tr , '\n'
/dev/sda1
/dev/sdb1
/dev/sdc1
/dev/sde1
Method #2 - using mdadm's query
You can use the query (-Q) & details (-D) along with verbos (-v) to do something similar:
$ mdadm -vQD /dev/md/raid1 | grep -o '/dev/s.*'
/dev/sdb1
/dev/sda1
/dev/sdc1
/dev/sde1
Method #3 - using /proc/mdstat
You can also parse the list of HDD members from the /proc/mdstat output like so:
$ grep 'md' /proc/mdstat | tr ' ' '\n' | sed -n 's/\[.*//p'
sde1
sdc1
sdb1
sda1
These will be missing the /dev portion but you can easily add that in manually like so:
$ grep 'md' /proc/mdstat | tr ' ' '\n' | sed -n 's|^|/dev/|;s/\[.*//p'
/dev/sde1
/dev/sdc1
/dev/sdb1
/dev/sda1
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
