Zend certified PHP/Magento developer

How much space does a Linux software RAID1 REALLY occupy on its component devices?

A precise answer to this question is important when shrinking the array and its components.

As an example, I have a RAID1 /dev/md0 set up on two partitions, /dev/sda1 and /dev/sdb1.
Both fdisk and /proc/partitions agree that these partitions are 248832 KiB (497664 sectors, exactly 243 MiB).
The array was most likely created using Debian installer to fill the available space.

mdadm --detail /dev/md0 reports:

        Array Size : 248640 (242.81 MiB 254.61 MB)
     Used Dev Size : 248640 (242.81 MiB 254.61 MB)

In /proc/partitions the size of /dev/md0 is also reported as 248640. The filesystem present on /dev/md0 also claims to occupy exactly this many 1 KiB blocks.

To summarize, the bounds are:

  • upper: 248832 KiB (size of each component device)
  • lower: 248640 KiB (size of contained filesystem)

Difference: 192 KiB.

Some of the 192 KiB are obviously needed for the array metadata (superblock and whatnot).

The question is now – how many sectors precisely does the array really occupy on the component devices?
In other words, how do I compute the smallest possible size for /dev/sd[ab]1 that will keep the array intact?

Whatever “Used Dev Size” means above (the internets are not sure), it clearly does take the metadata into account.

Looks like mdadm --examine /dev/sda1 reveals some more data:

          Magic : a92b4efc
        Version : 1.2
    Feature Map : 0x1
[...]
     Raid Level : raid1
   Raid Devices : 2
[...]
 Avail Dev Size : 497408 (242.88 MiB 254.67 MB)
     Array Size : 248640 (242.81 MiB 254.61 MB)
  Used Dev Size : 497280 (242.81 MiB 254.61 MB)
    Data Offset : 256 sectors
   Super Offset : 8 sectors
   Unused Space : before=176 sectors, after=128 sectors

Especially the “Avail Dev Size” looks interesting, since it seems to be exactly 128 KiB larger than the array size (per component).
This roughly matches the vague “about 128Kb of space at the end of the drive for the RAID superblock.” mentioned in –size description in the mdadm man page, if one assumes that the author actually meant “KiB” where they wrote “Kb”.

But I’m rather reluctant to assume this is the number I’m looking for.