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).
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.
Have yet to see a definitive answer to "remove raid metadata completely?"
here's mine (snippet of raid creation script when previous RAID detected):
Hope it saves someone else the time it cost me to sort this out.