大网数据广告活动
服务器运维问答

How do I list which drives are part of each RAID array?

· 52CE 我爱测

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?

问题原文

原帖链接 · 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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2014-12-09)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。