Linux software RAID: –auto-detect finds whole drive, not last partition

linuxmdadmraidsoftware-raid

My laptop, running Ubuntu Natty, is partitioned like so:

  • /dev/sda1: 500MB, /boot
  • /dev/sda2: 148GB, /

sda2 is a software RAID1 with 1 device. This is intentional — I periodically reshape the array with external drives.

When operating normally, the array looks like:

  • /dev/md0, [sda2]

This all works great, except that that when I boot, the array is detected as:

  • /dev/md127, [sda]

i.e. the whole drive, not the partition. I assume that this is because the 0.90 metadata format is stored at the end, but… surely it stores the start address or device somewhere?

mdadm --examine gives identical results for /dev/sda and /dev/sda2; I would expect it to fail on /dev/sda, but (again) I assume that this is because the metadata for sda2 happens to be in the correct place for sda as well.

Why is the wrong raid device detected automatically? Short of repartitioning the drive, is there any way I can prevent sda from being detected as a RAID array?

Best Answer

You should be able to prevent /dev/sda from being detected as an array device by appropriately crafting DEVICE entries in /etc/mdadm/mdadm.conf. Specifically, you can ensure that a partition (like /dev/sda2) is used---and a whole-drive device (like /dev/sda) is ignored---by specifying a DEVICE pattern like the following:

DEVICE /dev/sd[a-z][1-9]

You can also give multiple (glob-style) patterns, either separated by spaces, or in additional DEVICE lines.

Finally, be certain to comment-out/remove any line in mdadm.conf containing DEVICE partitions, so that mdadm does not consider the contents of /proc/partitions.