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

Why does mdadm --zero-superblock preserve file system information?

· 52CE 我爱测

I have two hard drive partitions, which I have combined into a RAID1 using mdadm , and created an ext4 filesystem on the resulting device. When I mdadm --zero-superblock the two partitions, and re-create the RAID, then the origin…

问题原文

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

I have two hard drive partitions, which I have combined into a RAID1 using mdadm, and created an ext4 filesystem on the resulting device.

When I mdadm --zero-superblock the two partitions, and re-create the RAID, then the original ext4 metadata is magically preserved.

Why is that?

And how can I tell mdadm to give me a truly new, uninitialised MD?


Details

How I create the RAID1 and file system:

ls /dev/sdc2  # partition 1
ls /dev/sdd2  # partition 2
mdadm --create --run --verbose /dev/md1 --level=1 --raid-devices=2 /dev/sdc2 /dev/sdd2
mkfs.ext4 -L mylabel /dev/md1

Wipe RAID1:

mdadm --stop /dev/md1
mdadm --zero-superblock /dev/sdc2
mdadm --zero-superblock /dev/sdd2

Recreate RAID1:

mdadm --create --run --verbose /dev/md1 --level=1 --raid-devices=2 /dev/sdc2 /dev/sdd2

Display device information (note wipefs without the -a flag doesn't wipe anything but just shows info):

# wipefs /dev/md1
offset               type
----------------------------------------------------------------
0x438                ext4   [filesystem]
                     LABEL: mylabel
                     UUID:  3d230d31-fb82-46ef-a4e0-e9473e05825c

LABEL: mylabel shows that the ext4 label "survived" the mdadm superblock wipe and RAID recreation.

How can that be?

I thought that after a superblock wipe and recreation, mdadm is supposed to present me with a "clean" view of the device (i.e. all zeros), unless a flag is given that turns that off (such as --assume-clean, which I haven't given).

社区高分解答

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

Because zero-ing the mdadm superblock only removes the metadata that describes the raid array, it doesn’t remove information about what is actually on the rest of the disk. This is actually a good thing, as it means you might be able to recover a volume when the array itself won’t assemble for some unfortunate reason.

And to be clear: because you’re creating the array using volumes and not whole-disk, the partition table isn’t touched by mdadm, so zero-ing the raid superblock isn’t going to affect the drive label nor the partition structure.

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

资料来源与适用范围

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

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

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