This is a repost of a question I asked on ServerFault and was automatically deleted for lack of activity. Let's hope it will have better luck here.

After performing a "check" (by writing check to /sys/class/block/md0/md/sync_action) of a md software RAID array with redundancy on Linux, the md subsystem will update the /sys/class/block/md0/md/mismatch_cnt virtual file with the number of sectors comprised in chunks that have a mismatch.

Unfortunately, it doesn't tell which chunk or sector they are.

On a RAID 1 array with 2 drives (for instance md0 on sda and sdb), one can do:

blockdev --flushbufs /dev/md0 /dev/sda /dev/sdb
cmp -l /dev/sda /dev/sdb > sda-sdb.diff

To find out which bytes differ, and then derive the sector and additional information (like which file is affected if there's a filesystem there).

But is there a way to get the same information for other RAID levels? For instance, with this RAID10 array:

$ cat /sys/class/block/md0/md/mismatch_cnt
$ cat /proc/mdstat
md0 : active raid10 sdd1[4] sdc1[3] sdb1[1] sda1[0]
      3906763776 blocks super 1.2 512K chunks 2 near-copies [4/4] [UUUU]

How would I know where the mismatches are on /dev/md0?

In this particular instance, the algorithm is not too complicated: we can use mdadm -E to find out where the data starts in the devices, and then sda1 is meant to be the same as sdb1 and sdc1 the same as sdd1, the first chunk of /dev/md0 is found in the first chunk of both sda1 and sda2, the second in the first chunk of both sdc1 and sdd1, so given the offset of a byte difference in a pair of devices, it's not two difficult to find out the corresponding offset in the md device, but I was hoping there was a way to avoid have to run down the algorithm manually

  • this is in man dmraid: -r [devpath...]: List all RAID devices ... sectors used and data offset into the device.... If -D is added to -r the RAID metadata gets dumped into a subdirectory named dmraid.format_name in files named devicename.dat. The byte offset where the metadata is located on the device is written into files named devicename.offsetand the size of the device in sectors into files named device‐name.size. I would suspect if it is useful it is only with that -D switch. That's a wild guess, though. – mikeserv Jan 20 '16 at 12:50
  • 1
    I added a line to my kernel to log the sector number during a RAID5 check, but now I'm not sure what to do with it: unix.stackexchange.com/questions/266432/…. RAID1/RAID10 mismatches can be spurious (esp. with swap on RAID), but you could add a similar printk to wherever the atomic64_add(STRIPE_SECTORS, &conf->mddev->resync_mismatches); happens for RAID1/RAID10. – Peter Cordes Feb 29 '16 at 5:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.