Mdadm –zero-superblock on disks with other partitions on them

mdadmpartition

I have three disks which used to hold an MD RAID5 array. I have since removed (or so I thought) this array and created partions for btrfs and swap space. On rebooting the machine, MD still binds the devices that used to hold the old array, causing the new filesystem to fail to mount.

It was suggested to me that the old superblocks of the raid arrays might be left behind causing MD to think it is a real array and thus binding the disks. The suggested solution was to use mdadm –zero-superblock to clear the superblock on the affected disks. However, I don't really know what this does with the disk. Since this disk holds partitions I don't really want to start zeroing parts of it blindly.

So what procedure should I follow to safely clear the MD superblocks without damaging the other partitions and file systems on the drives?

This question essentially asks the same thing, but there isn't a clear answer as to whether doing mdadm –zero-superblock on a repartitioned device is actually supposed to be safe: mdadm superblock hiding/shadowing partition

Best Answer

https://raid.wiki.kernel.org/index.php/RAID_superblock_formats

The superblock is 4K long and is written into a 64K aligned block that starts at least 64K and less than 128K from the end of the device (i.e. to get the address of the superblock round the size of the device down to a multiple of 64K and then subtract 64K). The available size of each device is the amount of space before the super block, so between 64K and 128K is lost when a device in incorporated into an MD array.

So, It's already too late and might be unsafe to use --zero-superblock, because we don't know is there any data or not - you must resize/shrink your current partition to -128K from the end of the x-RAID partition, then, wipe that part and grow partition back.

Other option 1: write large files to fill entire disk, it will overwrite RAID superblocks and it will not be recognizable by the mdadm.

Other option 2: similar to 1: https://unix.stackexchange.com/questions/44234/clear-unused-space-with-zeros-ext3-ext4