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

mdadm --zero-superblock for all devices of a mdraid?

· 52CE 我爱测

I found no way to remove a mdraid from a server with one command. I can stop it via mdadm --stop /dev/md0 But the superblock is still in the devices. mdadm --zero-superblock DEVICE needs every device (like /dev/sdb1) I know that …

问题原文

原帖链接 · guettli · CC BY-SA 4.0

I found no way to remove a mdraid from a server with one command.

I can stop it via mdadm --stop /dev/md0

But the superblock is still in the devices.

mdadm --zero-superblock DEVICE needs every device (like /dev/sdb1)

I know that I can do mdadm --detail /dev/md0 and then I see the devices.

I could write a fragile script to fetch the /dev/sd... strings from the output of mdadm --detail /dev/md0, but I would like to avoid this.

Is there a one-liner to remove the superblock from all devices of a mdraid?

I would like to avoid to parse the output of mdadm --detail, since this feels fragile.

已采纳解答

原帖链接 · shodanshok · CC BY-SA 4.0

If you know the array component devices, you can simply issue something as

mdadm --zero-superblock /dev/sd[abcd]

to remove the superblock from multiple devices with a single command.

Please note that mdadm checks for superblock before zeroing anything, so specifying sd* in the command above should only touch component disks, without writing anything to the others. However, I strongly suggest against doing that: any issues in the superblock detection routing, or using --force, are going to overwrite good data on non-component disks (causing data loss). From the man page:

If the device contains a valid md superblock, the block is overwritten with zeros. With --force the block where the superblock would be is overwritten even if it doesn't appear to be valid.

For the reason above, if you don't know the array component devices I suggest listing them via

blkid -t TYPE="linux_raid_member" -o device

and then zeroing the specific disks with mdadm --zero-superblock. This can be scripted with a single-line bash command:

for dev in `blkid -t TYPE="linux_raid_member" -o device`; do echo "zeroing $dev"; mdadm --zero-superblock $dev; done

As always, triple-check any such commands to avoid data loss.

EDIT: to discover the array component devices without resorting to parsing of mdadm --detail output, you can use lsblk. For example, on a test array created via loop devices:

# lsblk -l -n -s /dev/md127
md127   9:127  0  255M  0 raid1
loop5   7:5    0  256M  0 loop
loop6   7:6    0  256M  0 loop

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

资料来源与适用范围

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

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

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