+ @staticmethod
+ def _ZeroSuperblock(dev_path):
+ """Zero the possible locations for an MD superblock.
+
+ The zero-ing can't be done via ``mdadm --zero-superblock`` as that
+ fails in versions 2.x with the same error code as non-writable
+ device.
+
+ The superblocks are located at (negative values are relative to
+ the end of the block device):
+ - -128k to end for version 0.90 superblock
+ - -8k to -12k for version 1.0 superblock (included in the above)
+ - 0k to 4k for version 1.1 superblock
+ - 4k to 8k for version 1.2 superblock
+
+ To cover all situations, the zero-ing will be:
+ - 0k to 128k
+ - -128k to end
+
+ As such, the minimum device size must be 128k, otherwise we'll get
+ I/O errors.
+
+ Note that this function depends on the fact that one can open,
+ read and write block devices normally.
+
+ """
+ overwrite_size = 128 * 1024
+ empty_buf = '\0' * overwrite_size
+ fd = open(dev_path, "r+")
+ try:
+ fd.seek(0, 0)
+ p1 = fd.tell()
+ fd.write(empty_buf)
+ p2 = fd.tell()
+ logger.Debug("Zeroed %s from %d to %d" % (dev_path, p1, p2))
+ fd.seek(-overwrite_size, 2)
+ p1 = fd.tell()
+ fd.write(empty_buf)
+ p2 = fd.tell()
+ logger.Debug("Zeroed %s from %d to %d" % (dev_path, p1, p2))
+ finally:
+ fd.close()
+