2

If I build a RAID 5 array (specifically MD RAID on Linux) and then 1 of the drives disconnects for whatever reason, does that drive need to be rebuilt from scratch if:

  1. No data has been written to the array.
  2. Some data has been written to the array.

By "scratch", I mean full data rebuilt instead of rebuilding differential data since the last time the drive was online.

Livy
  • 163
  • 4

2 Answers2

1

That depends on.

When you disconnect your drive from RAID 5 array a complete array rebuild would be required once you put back drive on online. There is no way for the system to know that this drive are still has the same data as it had before going offline.

I mean while the drive are offline it's data could be modified by some other means. And "trusting" it while the drive are back online could be a disaster for data consistency.

You can enable a write-intent bitmap or journal mode of data consistency. See --bitmap & --consistency-policy options of mdadm for this. But in no way it guarantees that full rebuild won't take place after actually removing & reconnecting the drive I guess. For example if you have hot spare added to array it will start rebuilding array to hot spare as soon as you remove the drive.

NStorm
  • 1,312
  • 7
  • 18
1

This is the exact problem that a write-intent bitmap solves. When you create the array, specify --bitmap=internal on the command line. The bitmap records if a region of the array has been written. Depending on the size of the array, one bit might be 1 GiB, for instance.

During normal operation, the kernel sets bits to 1 just prior to writing a region. Then, once it knows that all writes have flushed to a region, it zeroes that bit out. If you fail a drive out of the array, so that the array is degraded, the bits just start accumulating 1's. They aren't cleared.

When you re-add the drive back into the array, md only synchronizes the regions that had been written, according to the bitmap.

You can add a bitmap to an existing array with --grow --bitmap=internal.

Mike Andrews
  • 383
  • 1
  • 7
  • Isn't write-intent bitmap only provides consistency during unclean shutdowns? OP has asked about drive totally disconnected from a host which leads to degraded state. Manpage of the mdadm tates that write-intent bitmaps are for unclean shutdown situations only. – NStorm Apr 23 '20 at 13:36
  • The `--re-add` codepath is different in this regard. If you can re-add a drive with a close enough event count, then it will be recovered using the write-intent bitmap. From the manpage, in the `--re-add` section: "However based on the event count on the device, the recovery may only require sections that are flagged a write-intent bitmap to be recovered or may not require any recovery at all." – Mike Andrews Apr 23 '20 at 22:09