1 .\" Copyright Neil Brown and others.
2 .\" This program is free software; you can redistribute it and/or modify
3 .\" it under the terms of the GNU General Public License as published by
4 .\" the Free Software Foundation; either version 2 of the License, or
5 .\" (at your option) any later version.
6 .\" See file COPYING in distribution for details.
10 md \- Multiple Device driver aka Linux Software RAID
20 driver provides virtual devices that are created from one or more
21 independent underlying devices. This array of devices often contains
22 redundancy and the devices are often disk drives, hence the acronym RAID
23 which stands for a Redundant Array of Independent Disks.
28 4 (striped array with parity device),
29 5 (striped array with distributed parity information),
30 6 (striped array with distributed dual redundancy information), and
31 10 (striped and mirrored).
32 If some number of underlying devices fails while using one of these
33 levels, the array will continue to function; this number is one for
34 RAID levels 4 and 5, two for RAID level 6, and all but one (N-1) for
35 RAID level 1, and dependent on configuration for level 10.
38 also supports a number of pseudo RAID (non-redundant) configurations
39 including RAID0 (striped array), LINEAR (catenated array),
40 MULTIPATH (a set of different interfaces to the same device),
41 and FAULTY (a layer over a single device into which errors can be injected).
44 Each device in an array may have some
46 stored in the device. This metadata is sometimes called a
48 The metadata records information about the structure and state of the array.
49 This allows the array to be reliably re-assembled after a shutdown.
51 From Linux kernel version 2.6.10,
53 provides support for two different formats of metadata, and
54 other formats can be added. Prior to this release, only one format is
57 The common format \(em known as version 0.90 \(em has
58 a superblock that is 4K long and is written into a 64K aligned block that
59 starts at least 64K and less than 128K from the end of the device
60 (i.e. to get the address of the superblock round the size of the
61 device down to a multiple of 64K and then subtract 64K).
62 The available size of each device is the amount of space before the
63 super block, so between 64K and 128K is lost when a device in
64 incorporated into an MD array.
65 This superblock stores multi-byte fields in a processor-dependent
66 manner, so arrays cannot easily be moved between computers with
69 The new format \(em known as version 1 \(em has a superblock that is
70 normally 1K long, but can be longer. It is normally stored between 8K
71 and 12K from the end of the device, on a 4K boundary, though
72 variations can be stored at the start of the device (version 1.1) or 4K from
73 the start of the device (version 1.2).
74 This metadata format stores multibyte data in a
75 processor-independent format and supports up to hundreds of
76 component devices (version 0.90 only supports 28).
78 The metadata contains, among other things:
81 The manner in which the devices are arranged into the array
82 (LINEAR, RAID0, RAID1, RAID4, RAID5, RAID10, MULTIPATH).
85 a 128 bit Universally Unique Identifier that identifies the array that
89 When a version 0.90 array is being reshaped (e.g. adding extra devices
90 to a RAID5), the version number is temporarily set to 0.91. This
91 ensures that if the reshape process is stopped in the middle (e.g. by
92 a system crash) and the machine boots into an older kernel that does
93 not support reshaping, then the array will not be assembled (which
94 would cause data corruption) but will be left untouched until a kernel
95 that can complete the reshape processes is used.
97 .SS ARRAYS WITHOUT METADATA
98 While it is usually best to create arrays with superblocks so that
99 they can be assembled reliably, there are some circumstances when an
100 array without superblocks is preferred. These include:
103 Early versions of the
105 driver only supported LINEAR and RAID0 configurations and did not use
106 a superblock (which is less critical with these configurations).
107 While such arrays should be rebuilt with superblocks if possible,
109 continues to support them.
112 Being a largely transparent layer over a different device, the FAULTY
113 personality doesn't gain anything from having a superblock.
116 It is often possible to detect devices which are different paths to
117 the same storage directly rather than having a distinctive superblock
118 written to the device and searched for on all paths. In this case,
119 a MULTIPATH array with no superblock makes sense.
122 In some configurations it might be desired to create a RAID1
123 configuration that does not use a superblock, and to maintain the state of
124 the array elsewhere. While not encouraged for general use, it does
125 have special-purpose uses and is supported.
127 .SS ARRAYS WITH EXTERNAL METADATA
129 From release 2.6.28, the
131 driver supports arrays with externally managed metadata. That is,
132 the metadata is not managed by the kernel but rather by a user-space
133 program which is external to the kernel. This allows support for a
134 variety of metadata formats without cluttering the kernel with lots of
138 is able to communicate with the user-space program through various
139 sysfs attributes so that it can make appropriate changes to the
140 metadata \- for example to mark a device as faulty. When necessary,
142 will wait for the program to acknowledge the event by writing to a
146 contains more detail about this interaction.
149 Many metadata formats use a single block of metadata to describe a
150 number of different arrays which all use the same set of devices.
151 In this case it is helpful for the kernel to know about the full set
152 of devices as a whole. This set is known to md as a
156 array with externally managed metadata and with device offset and size
157 so that it just covers the metadata part of the devices. The
158 remainder of each device is available to be incorporated into various
163 A LINEAR array simply catenates the available space on each
164 drive to form one large virtual drive.
166 One advantage of this arrangement over the more common RAID0
167 arrangement is that the array may be reconfigured at a later time with
168 an extra drive, so the array is made bigger without disturbing the
169 data that is on the array. This can even be done on a live
172 If a chunksize is given with a LINEAR array, the usable space on each
173 device is rounded down to a multiple of this chunksize.
177 A RAID0 array (which has zero redundancy) is also known as a
179 A RAID0 array is configured at creation with a
181 which must be a power of two (prior to Linux 2.6.31), and at least 4
184 The RAID0 driver assigns the first chunk of the array to the first
185 device, the second chunk to the second device, and so on until all
186 drives have been assigned one chunk. This collection of chunks forms a
188 Further chunks are gathered into stripes in the same way, and are
189 assigned to the remaining space in the drives.
191 If devices in the array are not all the same size, then once the
192 smallest device has been exhausted, the RAID0 driver starts
193 collecting chunks into smaller stripes that only span the drives which
194 still have remaining space.
196 A bug was introduced in linux 3.14 which changed the layout of blocks in
197 a RAID0 beyond the region that is striped over all devices. This bug
198 does not affect an array with all devices the same size, but can affect
201 Linux 5.4 (and some stable kernels to which the change was backported)
202 will not normally assemble such an array as it cannot know which layout
203 to use. There is a module parameter "raid0.default_layout" which can be
204 set to "1" to force the kernel to use the pre-3.14 layout or to "2" to
205 force it to use the 3.14-and-later layout. when creating a new RAID0
208 will record the chosen layout in the metadata in a way that allows newer
209 kernels to assemble the array without needing a module parameter.
213 A RAID1 array is also known as a mirrored set (though mirrors tend to
214 provide reflected images, which RAID1 does not) or a plex.
216 Once initialised, each device in a RAID1 array contains exactly the
217 same data. Changes are written to all devices in parallel. Data is
218 read from any one device. The driver attempts to distribute read
219 requests across all devices to maximise performance.
221 All devices in a RAID1 array should be the same size. If they are
222 not, then only the amount of space available on the smallest device is
223 used (any extra space on other devices is wasted).
225 Note that the read balancing done by the driver does not make the RAID1
226 performance profile be the same as for RAID0; a single stream of
227 sequential input will not be accelerated (e.g. a single dd), but
228 multiple sequential streams or a random workload will use more than one
229 spindle. In theory, having an N-disk RAID1 will allow N sequential
230 threads to read from all disks.
232 Individual devices in a RAID1 can be marked as "write-mostly".
233 These drives are excluded from the normal read balancing and will only
234 be read from when there is no other option. This can be useful for
235 devices connected over a slow link.
239 A RAID4 array is like a RAID0 array with an extra device for storing
240 parity. This device is the last of the active devices in the
241 array. Unlike RAID0, RAID4 also requires that all stripes span all
242 drives, so extra space on devices that are larger than the smallest is
245 When any block in a RAID4 array is modified, the parity block for that
246 stripe (i.e. the block in the parity device at the same device offset
247 as the stripe) is also modified so that the parity block always
248 contains the "parity" for the whole stripe. I.e. its content is
249 equivalent to the result of performing an exclusive-or operation
250 between all the data blocks in the stripe.
252 This allows the array to continue to function if one device fails.
253 The data that was on that device can be calculated as needed from the
254 parity block and the other data blocks.
258 RAID5 is very similar to RAID4. The difference is that the parity
259 blocks for each stripe, instead of being on a single device, are
260 distributed across all devices. This allows more parallelism when
261 writing, as two different block updates will quite possibly affect
262 parity blocks on different devices so there is less contention.
264 This also allows more parallelism when reading, as read requests are
265 distributed over all the devices in the array instead of all but one.
269 RAID6 is similar to RAID5, but can handle the loss of any \fItwo\fP
270 devices without data loss. Accordingly, it requires N+2 drives to
271 store N drives worth of data.
273 The performance for RAID6 is slightly lower but comparable to RAID5 in
274 normal mode and single disk failure mode. It is very slow in dual
275 disk failure mode, however.
279 RAID10 provides a combination of RAID1 and RAID0, and is sometimes known
280 as RAID1+0. Every datablock is duplicated some number of times, and
281 the resulting collection of datablocks are distributed over multiple
284 When configuring a RAID10 array, it is necessary to specify the number
285 of replicas of each data block that are required (this will usually
286 be\ 2) and whether their layout should be "near", "far" or "offset"
287 (with "offset" being available since Linux\ 2.6.18).
289 .B About the RAID10 Layout Examples:
291 The examples below visualise the chunk distribution on the underlying
292 devices for the respective layout.
294 For simplicity it is assumed that the size of the chunks equals the
295 size of the blocks of the underlying devices as well as those of the
296 RAID10 device exported by the kernel (for example \fB/dev/md/\fPname).
298 Therefore the chunks\ /\ chunk numbers map directly to the blocks\ /\
299 block addresses of the exported RAID10 device.
301 Decimal numbers (0,\ 1, 2,\ ...) are the chunks of the RAID10 and due
302 to the above assumption also the blocks and block addresses of the
303 exported RAID10 device.
305 Repeated numbers mean copies of a chunk\ /\ block (obviously on
306 different underlying devices).
308 Hexadecimal numbers (0x00,\ 0x01, 0x02,\ ...) are the block addresses
309 of the underlying devices.
313 When "near" replicas are chosen, the multiple copies of a given chunk are laid
314 out consecutively ("as close to each other as possible") across the stripes of
317 With an even number of devices, they will likely (unless some misalignment is
318 present) lay at the very same offset on the different devices.
320 This is as the "classic" RAID1+0; that is two groups of mirrored devices (in the
321 example below the groups Device\ #1\ /\ #2 and Device\ #3\ /\ #4 are each a
322 RAID1) both in turn forming a striped RAID0.
325 .B Example with 2\ copies per chunk and an even number\ (4) of devices:
330 | - | - | - | - | - |
331 | C | C | C | C | C |
332 | C | C | C | C | C |
333 | C | C | C | C | C |
334 | C | C | C | C | C |
335 | C | C | C | C | C |
336 | C | C | C | C | C |
337 | - | - | - | - | - |
343 ;Device #1;Device #2;Device #3;Device #4
346 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.
348 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.
350 ;\\---------v---------/;\\---------v---------/
352 ;\\---------------------v---------------------/
357 .B Example with 2\ copies per chunk and an odd number\ (5) of devices:
361 C | C | C | C | C | C |
362 | - | - | - | - | - | - |
363 | C | C | C | C | C | C |
364 | C | C | C | C | C | C |
365 | C | C | C | C | C | C |
366 | C | C | C | C | C | C |
367 | C | C | C | C | C | C |
368 | C | C | C | C | C | C |
369 | - | - | - | - | - | - |
372 ;Dev #1;Dev #2;Dev #3;Dev #4;Dev #5
375 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.
377 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.
378 0x80;317;318;318;319;319
384 When "far" replicas are chosen, the multiple copies of a given chunk
385 are laid out quite distant ("as far as reasonably possible") from each
388 First a complete sequence of all data blocks (that is all the data one
389 sees on the exported RAID10 block device) is striped over the
390 devices. Then another (though "shifted") complete sequence of all data
391 blocks; and so on (in the case of more than 2\ copies per chunk).
393 The "shift" needed to prevent placing copies of the same chunks on the
394 same devices is actually a cyclic permutation with offset\ 1 of each
395 of the stripes within a complete sequence of chunks.
397 The offset\ 1 is relative to the previous complete sequence of chunks,
398 so in case of more than 2\ copies per chunk one gets the following
401 1.\ complete sequence of chunks: offset\ =\ \ 0
403 2.\ complete sequence of chunks: offset\ =\ \ 1
405 3.\ complete sequence of chunks: offset\ =\ \ 2
409 n.\ complete sequence of chunks: offset\ =\ n-1
412 .B Example with 2\ copies per chunk and an even number\ (4) of devices:
417 | - | - | - | - | - |
418 | C | C | C | C | C | L
419 | C | C | C | C | C | L
420 | C | C | C | C | C | L
421 | C | C | C | C | C | L
422 | C | C | C | C | C | L
423 | C | C | C | C | C | L
424 | C | C | C | C | C | L
425 | C | C | C | C | C | L
426 | C | C | C | C | C | L
427 | C | C | C | C | C | L
428 | C | C | C | C | C | L
429 | C | C | C | C | C | L
430 | - | - | - | - | - |
433 ;Device #1;Device #2;Device #3;Device #4
437 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;:
439 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;:
440 0x40;252;253;254;255;/
443 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;:
445 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;:
446 0x80;255;252;253;254;/
451 .B Example with 2\ copies per chunk and an odd number\ (5) of devices:
455 C | C | C | C | C | C |
456 | - | - | - | - | - | - |
457 | C | C | C | C | C | C | L
458 | C | C | C | C | C | C | L
459 | C | C | C | C | C | C | L
460 | C | C | C | C | C | C | L
461 | C | C | C | C | C | C | L
462 | C | C | C | C | C | C | L
463 | C | C | C | C | C | C | L
464 | C | C | C | C | C | C | L
465 | C | C | C | C | C | C | L
466 | C | C | C | C | C | C | L
467 | C | C | C | C | C | C | L
468 | C | C | C | C | C | C | L
469 | - | - | - | - | - | - |
472 ;Dev #1;Dev #2;Dev #3;Dev #4;Dev #5
476 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;:
478 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;:
479 0x40;315;316;317;318;319;/
481 0x42;9;5;6;7;8;> [#]~
482 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;:
484 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;:
485 0x80;319;315;316;317;318;/
489 With [#]\ being the complete sequence of chunks and [#]~\ the cyclic permutation
490 with offset\ 1 thereof (in the case of more than 2 copies per chunk there would
491 be ([#]~)~,\ (([#]~)~)~,\ ...).
493 The advantage of this layout is that MD can easily spread sequential reads over
494 the devices, making them similar to RAID0 in terms of speed.
496 The cost is more seeking for writes, making them substantially slower.
499 \fB"offset" Layout\fP
500 When "offset" replicas are chosen, all the copies of a given chunk are
501 striped consecutively ("offset by the stripe length after each other")
504 Explained in detail, <number of devices> consecutive chunks are
505 striped over the devices, immediately followed by a "shifted" copy of
506 these chunks (and by further such "shifted" copies in the case of more
507 than 2\ copies per chunk).
509 This pattern repeats for all further consecutive chunks of the
510 exported RAID10 device (in other words: all further data blocks).
512 The "shift" needed to prevent placing copies of the same chunks on the
513 same devices is actually a cyclic permutation with offset\ 1 of each
514 of the striped copies of <number of devices> consecutive chunks.
516 The offset\ 1 is relative to the previous striped copy of <number of
517 devices> consecutive chunks, so in case of more than 2\ copies per
518 chunk one gets the following offsets:
520 1.\ <number of devices> consecutive chunks: offset\ =\ \ 0
522 2.\ <number of devices> consecutive chunks: offset\ =\ \ 1
524 3.\ <number of devices> consecutive chunks: offset\ =\ \ 2
528 n.\ <number of devices> consecutive chunks: offset\ =\ n-1
531 .B Example with 2\ copies per chunk and an even number\ (4) of devices:
536 | - | - | - | - | - |
537 | C | C | C | C | C | L
538 | C | C | C | C | C | L
539 | C | C | C | C | C | L
540 | C | C | C | C | C | L
541 | C | C | C | C | C | L
542 | C | C | C | C | C | L
543 | C | C | C | C | C | L
544 | C | C | C | C | C | L
545 | C | C | C | C | C | L
546 | - | - | - | - | - |
549 ;Device #1;Device #2;Device #3;Device #4
555 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;) \.\.\.
557 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;) \.\.\.
558 0x79;251;252;253;254;) EX
559 0x80;254;251;252;253;) EX~
564 .B Example with 2\ copies per chunk and an odd number\ (5) of devices:
568 C | C | C | C | C | C |
569 | - | - | - | - | - | - |
570 | C | C | C | C | C | C | L
571 | C | C | C | C | C | C | L
572 | C | C | C | C | C | C | L
573 | C | C | C | C | C | C | L
574 | C | C | C | C | C | C | L
575 | C | C | C | C | C | C | L
576 | C | C | C | C | C | C | L
577 | C | C | C | C | C | C | L
578 | C | C | C | C | C | C | L
579 | - | - | - | - | - | - |
582 ;Dev #1;Dev #2;Dev #3;Dev #4;Dev #5
588 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;) \.\.\.
590 \.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;\.\.\.;) \.\.\.
591 0x79;314;315;316;317;318;) EX
592 0x80;318;314;315;316;317;) EX~
596 With AA,\ AB,\ ..., AZ,\ BA,\ ... being the sets of <number of devices> consecutive
597 chunks and AA~,\ AB~,\ ..., AZ~,\ BA~,\ ... the cyclic permutations with offset\ 1
598 thereof (in the case of more than 2 copies per chunk there would be (AA~)~,\ ...
599 as well as ((AA~)~)~,\ ... and so on).
601 This should give similar read characteristics to "far" if a suitably large chunk
602 size is used, but without as much seeking for writes.
606 It should be noted that the number of devices in a RAID10 array need
607 not be a multiple of the number of replica of each data block; however,
608 there must be at least as many devices as replicas.
610 If, for example, an array is created with 5 devices and 2 replicas,
611 then space equivalent to 2.5 of the devices will be available, and
612 every block will be stored on two different devices.
614 Finally, it is possible to have an array with both "near" and "far"
615 copies. If an array is configured with 2 near copies and 2 far
616 copies, then there will be a total of 4 copies of each block, each on
617 a different drive. This is an artifact of the implementation and is
618 unlikely to be of real value.
622 MULTIPATH is not really a RAID at all as there is only one real device
623 in a MULTIPATH md array. However there are multiple access points
624 (paths) to this device, and one of these paths might fail, so there
625 are some similarities.
627 A MULTIPATH array is composed of a number of logically different
628 devices, often fibre channel interfaces, that all refer the the same
629 real device. If one of these interfaces fails (e.g. due to cable
630 problems), the MULTIPATH driver will attempt to redirect requests to
633 The MULTIPATH drive is not receiving any ongoing development and
634 should be considered a legacy driver. The device-mapper based
635 multipath drivers should be preferred for new installations.
638 The FAULTY md module is provided for testing purposes. A FAULTY array
639 has exactly one component device and is normally assembled without a
640 superblock, so the md array created provides direct access to all of
641 the data in the component device.
643 The FAULTY module may be requested to simulate faults to allow testing
644 of other md levels or of filesystems. Faults can be chosen to trigger
645 on read requests or write requests, and can be transient (a subsequent
646 read/write at the address will probably succeed) or persistent
647 (subsequent read/write of the same address will fail). Further, read
648 faults can be "fixable" meaning that they persist until a write
649 request at the same address.
651 Fault types can be requested with a period. In this case, the fault
652 will recur repeatedly after the given number of requests of the
653 relevant type. For example if persistent read faults have a period of
654 100, then every 100th read request would generate a fault, and the
655 faulty sector would be recorded so that subsequent reads on that
656 sector would also fail.
658 There is a limit to the number of faulty sectors that are remembered.
659 Faults generated after this limit is exhausted are treated as
662 The list of faulty sectors can be flushed, and the active list of
663 failure modes can be cleared.
667 When changes are made to a RAID1, RAID4, RAID5, RAID6, or RAID10 array
668 there is a possibility of inconsistency for short periods of time as
669 each update requires at least two block to be written to different
670 devices, and these writes probably won't happen at exactly the same
671 time. Thus if a system with one of these arrays is shutdown in the
672 middle of a write operation (e.g. due to power failure), the array may
675 To handle this situation, the md driver marks an array as "dirty"
676 before writing any data to it, and marks it as "clean" when the array
677 is being disabled, e.g. at shutdown. If the md driver finds an array
678 to be dirty at startup, it proceeds to correct any possibly
679 inconsistency. For RAID1, this involves copying the contents of the
680 first drive onto all other drives. For RAID4, RAID5 and RAID6 this
681 involves recalculating the parity for each stripe and making sure that
682 the parity block has the correct data. For RAID10 it involves copying
683 one of the replicas of each block onto all the others. This process,
684 known as "resynchronising" or "resync" is performed in the background.
685 The array can still be used, though possibly with reduced performance.
687 If a RAID4, RAID5 or RAID6 array is degraded (missing at least one
688 drive, two for RAID6) when it is restarted after an unclean shutdown, it cannot
689 recalculate parity, and so it is possible that data might be
690 undetectably corrupted. The 2.4 md driver
692 alert the operator to this condition. The 2.6 md driver will fail to
693 start an array in this condition without manual intervention, though
694 this behaviour can be overridden by a kernel parameter.
698 If the md driver detects a write error on a device in a RAID1, RAID4,
699 RAID5, RAID6, or RAID10 array, it immediately disables that device
700 (marking it as faulty) and continues operation on the remaining
701 devices. If there are spare drives, the driver will start recreating
702 on one of the spare drives the data which was on that failed drive,
703 either by copying a working drive in a RAID1 configuration, or by
704 doing calculations with the parity block on RAID4, RAID5 or RAID6, or
705 by finding and copying originals for RAID10.
707 In kernels prior to about 2.6.15, a read error would cause the same
708 effect as a write error. In later kernels, a read-error will instead
709 cause md to attempt a recovery by overwriting the bad block. i.e. it
710 will find the correct data from elsewhere, write it over the block
711 that failed, and then try to read it back again. If either the write
712 or the re-read fail, md will treat the error the same way that a write
713 error is treated, and will fail the whole device.
715 While this recovery process is happening, the md driver will monitor
716 accesses to the array and will slow down the rate of recovery if other
717 activity is happening, so that normal access to the array will not be
718 unduly affected. When no other activity is happening, the recovery
719 process proceeds at full speed. The actual speed targets for the two
720 different situations can be controlled by the
724 control files mentioned below.
726 .SS SCRUBBING AND MISMATCHES
728 As storage devices can develop bad blocks at any time it is valuable
729 to regularly read all blocks on all devices in an array so as to catch
730 such bad blocks early. This process is called
733 md arrays can be scrubbed by writing either
741 directory for the device.
743 Requesting a scrub will cause
745 to read every block on every device in the array, and check that the
746 data is consistent. For RAID1 and RAID10, this means checking that the copies
747 are identical. For RAID4, RAID5, RAID6 this means checking that the
748 parity block is (or blocks are) correct.
750 If a read error is detected during this process, the normal read-error
751 handling causes correct data to be found from other devices and to be
752 written back to the faulty device. In many case this will
757 If all blocks read successfully but are found to not be consistent,
758 then this is regarded as a
763 was used, then no action is taken to handle the mismatch, it is simply
767 was used, then a mismatch will be repaired in the same way that
769 repairs arrays. For RAID5/RAID6 new parity blocks are written. For RAID1/RAID10,
770 all but one block are overwritten with the content of that one block.
772 A count of mismatches is recorded in the
775 .IR md/mismatch_cnt .
776 This is set to zero when a
777 scrub starts and is incremented whenever a sector is
778 found that is a mismatch.
780 normally works in units much larger than a single sector and when it
781 finds a mismatch, it does not determine exactly how many actual sectors were
782 affected but simply adds the number of sectors in the IO unit that was
783 used. So a value of 128 could simply mean that a single 64KB check
784 found an error (128 x 512bytes = 64KB).
786 If an array is created by
790 then a subsequent check could be expected to find some mismatches.
792 On a truly clean RAID5 or RAID6 array, any mismatches should indicate
793 a hardware problem at some level - software issues should never cause
796 However on RAID1 and RAID10 it is possible for software issues to
797 cause a mismatch to be reported. This does not necessarily mean that
798 the data on the array is corrupted. It could simply be that the
799 system does not care what is stored on that part of the array - it is
802 The most likely cause for an unexpected mismatch on RAID1 or RAID10
803 occurs if a swap partition or swap file is stored on the array.
805 When the swap subsystem wants to write a page of memory out, it flags
806 the page as 'clean' in the memory manager and requests the swap device
807 to write it out. It is quite possible that the memory will be
808 changed while the write-out is happening. In that case the 'clean'
809 flag will be found to be clear when the write completes and so the
810 swap subsystem will simply forget that the swapout had been attempted,
811 and will possibly choose a different page to write out.
813 If the swap device was on RAID1 (or RAID10), then the data is sent
814 from memory to a device twice (or more depending on the number of
815 devices in the array). Thus it is possible that the memory gets changed
816 between the times it is sent, so different data can be written to
817 the different devices in the array. This will be detected by
819 as a mismatch. However it does not reflect any corruption as the
820 block where this mismatch occurs is being treated by the swap system as
821 being empty, and the data will never be read from that block.
823 It is conceivable for a similar situation to occur on non-swap files,
824 though it is less likely.
828 value can not be interpreted very reliably on RAID1 or RAID10,
829 especially when the device is used for swap.
832 .SS BITMAP WRITE-INTENT LOGGING
836 supports a bitmap based write-intent log. If configured, the bitmap
837 is used to record which blocks of the array may be out of sync.
838 Before any write request is honoured, md will make sure that the
839 corresponding bit in the log is set. After a period of time with no
840 writes to an area of the array, the corresponding bit will be cleared.
842 This bitmap is used for two optimisations.
844 Firstly, after an unclean shutdown, the resync process will consult
845 the bitmap and only resync those blocks that correspond to bits in the
846 bitmap that are set. This can dramatically reduce resync time.
848 Secondly, when a drive fails and is removed from the array, md stops
849 clearing bits in the intent log. If that same drive is re-added to
850 the array, md will notice and will only recover the sections of the
851 drive that are covered by bits in the intent log that are set. This
852 can allow a device to be temporarily removed and reinserted without
853 causing an enormous recovery cost.
855 The intent log can be stored in a file on a separate device, or it can
856 be stored near the superblocks of an array which has superblocks.
858 It is possible to add an intent log to an active array, or remove an
859 intent log if one is present.
861 In 2.6.13, intent bitmaps are only supported with RAID1. Other levels
862 with redundancy are supported from 2.6.15.
866 From Linux 3.5 each device in an
868 array can store a list of known-bad-blocks. This list is 4K in size
869 and usually positioned at the end of the space between the superblock
872 When a block cannot be read and cannot be repaired by writing data
873 recovered from other devices, the address of the block is stored in
874 the bad block list. Similarly if an attempt to write a block fails,
875 the address will be recorded as a bad block. If attempting to record
876 the bad block fails, the whole device will be marked faulty.
878 Attempting to read from a known bad block will cause a read error.
879 Attempting to write to a known bad block will be ignored if any write
880 errors have been reported by the device. If there have been no write
881 errors then the data will be written to the known bad block and if
882 that succeeds, the address will be removed from the list.
884 This allows an array to fail more gracefully - a few blocks on
885 different devices can be faulty without taking the whole array out of
888 The list is particularly useful when recovering to a spare. If a few blocks
889 cannot be read from the other devices, the bulk of the recovery can
890 complete and those few bad blocks will be recorded in the bad block list.
892 .SS RAID456 WRITE JOURNAL
894 Due to non-atomicity nature of RAID write operations, interruption of
895 write operations (system crash, etc.) to RAID456 array can lead to
896 inconsistent parity and data loss (so called RAID-5 write hole).
898 To plug the write hole, from Linux 4.4 (to be confirmed),
900 supports write ahead journal for RAID456. When the array is created,
901 an additional journal device can be added to the array through
903 option. The RAID write journal works similar to file system journals.
904 Before writing to the data disks, md persists data AND parity of the
905 stripe to the journal device. After crashes, md searches the journal
906 device for incomplete write operations, and replay them to the data
909 When the journal device fails, the RAID array is forced to run in
916 supports WRITE-BEHIND on RAID1 arrays.
918 This allows certain devices in the array to be flagged as
920 MD will only read from such devices if there is no
923 If a write-intent bitmap is also provided, write requests to
924 write-mostly devices will be treated as write-behind requests and md
925 will not wait for writes to those requests to complete before
926 reporting the write as complete to the filesystem.
928 This allows for a RAID1 with WRITE-BEHIND to be used to mirror data
929 over a slow link to a remote computer (providing the link isn't too
930 slow). The extra latency of the remote link will not slow down normal
931 operations, but the remote system will still have a reasonably
932 up-to-date copy of all data.
939 supports FAILFAST for RAID1 and RAID10 arrays. This is a flag that
940 can be set on individual drives, though it is usually set on all
941 drives, or no drives.
945 sends an I/O request to a drive that is marked as FAILFAST, and when
946 the array could survive the loss of that drive without losing data,
948 will request that the underlying device does not perform any retries.
949 This means that a failure will be reported to
951 promptly, and it can mark the device as faulty and continue using the
954 cannot control the timeout that the underlying devices use to
955 determine failure. Any changes desired to that timeout must be set
956 explictly on the underlying device, separately from using
959 If a FAILFAST request does fail, and if it is still safe to mark the
960 device as faulty without data loss, that will be done and the array
961 will continue functioning on a reduced number of devices. If it is not
962 possible to safely mark the device as faulty,
964 will retry the request without disabling retries in the underlying
967 will not attempt to repair read errors on a device marked as FAILFAST
968 by writing out the correct. It will just mark the device as faulty.
970 FAILFAST is appropriate for storage arrays that have a low probability
971 of true failure, but will sometimes introduce unacceptable delays to
972 I/O requests while performing internal maintenance. The value of
973 setting FAILFAST involves a trade-off. The gain is that the chance of
974 unacceptable delays is substantially reduced. The cost is that the
975 unlikely event of data-loss on one device is slightly more likely to
976 result in data-loss for the array.
978 When a device in an array using FAILFAST is marked as faulty, it will
979 usually become usable again in a short while.
981 makes no attempt to detect that possibility. Some separate
982 mechanism, tuned to the specific details of the expected failure modes,
983 needs to be created to monitor devices to see when they return to full
984 functionality, and to then re-add them to the array. In order of
985 this "re-add" functionality to be effective, an array using FAILFAST
986 should always have a write-intent bitmap.
993 is the processes of re-arranging the data stored in each stripe into a
994 new layout. This might involve changing the number of devices in the
995 array (so the stripes are wider), changing the chunk size (so stripes
996 are deeper or shallower), or changing the arrangement of data and
997 parity (possibly changing the RAID level, e.g. 1 to 5 or 5 to 6).
999 As of Linux 2.6.35, md can reshape a RAID4, RAID5, or RAID6 array to
1000 have a different number of devices (more or fewer) and to have a
1001 different layout or chunk size. It can also convert between these
1002 different RAID levels. It can also convert between RAID0 and RAID10,
1003 and between RAID0 and RAID4 or RAID5.
1004 Other possibilities may follow in future kernels.
1006 During any stripe process there is a 'critical section' during which
1007 live data is being overwritten on disk. For the operation of
1008 increasing the number of drives in a RAID5, this critical section
1009 covers the first few stripes (the number being the product of the old
1010 and new number of devices). After this critical section is passed,
1011 data is only written to areas of the array which no longer hold live
1012 data \(em the live data has already been located away.
1014 For a reshape which reduces the number of devices, the 'critical
1015 section' is at the end of the reshape process.
1017 md is not able to ensure data preservation if there is a crash
1018 (e.g. power failure) during the critical section. If md is asked to
1019 start an array which failed during a critical section of restriping,
1020 it will fail to start the array.
1022 To deal with this possibility, a user-space program must
1024 Disable writes to that section of the array (using the
1028 take a copy of the data somewhere (i.e. make a backup),
1030 allow the process to continue and invalidate the backup and restore
1031 write access once the critical section is passed, and
1033 provide for restoring the critical data before restarting the array
1034 after a system crash.
1038 versions from 2.4 do this for growing a RAID5 array.
1040 For operations that do not change the size of the array, like simply
1041 increasing chunk size, or converting RAID5 to RAID6 with one extra
1042 device, the entire process is the critical section. In this case, the
1043 restripe will need to progress in stages, as a section is suspended,
1044 backed up, restriped, and released.
1047 Each block device appears as a directory in
1049 (which is usually mounted at
1051 For MD devices, this directory will contain a subdirectory called
1053 which contains various files for providing access to information about
1056 This interface is documented more fully in the file
1057 .B Documentation/md.txt
1058 which is distributed with the kernel sources. That file should be
1059 consulted for full documentation. The following are just a selection
1060 of attribute files that are available.
1063 .B md/sync_speed_min
1064 This value, if set, overrides the system-wide setting in
1065 .B /proc/sys/dev/raid/speed_limit_min
1066 for this array only.
1069 to this file will cause the system-wide setting to have effect.
1072 .B md/sync_speed_max
1073 This is the partner of
1074 .B md/sync_speed_min
1076 .B /proc/sys/dev/raid/speed_limit_max
1081 This can be used to monitor and control the resync/recovery process of
1083 In particular, writing "check" here will cause the array to read all
1084 data block and check that they are consistent (e.g. parity is correct,
1085 or all mirror replicas are the same). Any discrepancies found are
1089 A count of problems found will be stored in
1090 .BR md/mismatch_count .
1092 Alternately, "repair" can be written which will cause the same check
1093 to be performed, but any errors will be corrected.
1095 Finally, "idle" can be written to stop the check/repair process.
1098 .B md/stripe_cache_size
1099 This is only available on RAID5 and RAID6. It records the size (in
1100 pages per device) of the stripe cache which is used for synchronising
1101 all write operations to the array and all read operations if the array
1102 is degraded. The default is 256. Valid values are 17 to 32768.
1103 Increasing this number can increase performance in some situations, at
1104 some cost in system memory. Note, setting this value too high can
1105 result in an "out of memory" condition for the system.
1107 memory_consumed = system_page_size * nr_disks * stripe_cache_size
1110 .B md/preread_bypass_threshold
1111 This is only available on RAID5 and RAID6. This variable sets the
1112 number of times MD will service a full-stripe-write before servicing a
1113 stripe that requires some "prereading". For fairness this defaults to
1114 1. Valid values are 0 to stripe_cache_size. Setting this to 0
1115 maximizes sequential-write throughput at the cost of fairness to threads
1116 doing small or random writes.
1119 .B md/bitmap/backlog
1120 The value stored in the file only has any effect on RAID1 when write-mostly
1121 devices are active, and write requests to those devices are proceed in the
1124 This variable sets a limit on the number of concurrent background writes,
1125 the valid values are 0 to 16383, 0 means that write-behind is not allowed,
1126 while any other number means it can happen. If there are more write requests
1127 than the number, new writes will by synchronous.
1130 .B md/bitmap/can_clear
1131 This is for externally managed bitmaps, where the kernel writes the bitmap
1132 itself, but metadata describing the bitmap is managed by mdmon or similar.
1134 When the array is degraded, bits mustn't be cleared. When the array becomes
1135 optimal again, bit can be cleared, but first the metadata needs to record
1136 the current event count. So md sets this to 'false' and notifies mdmon,
1137 then mdmon updates the metadata and writes 'true'.
1139 There is no code in mdmon to actually do this, so maybe it doesn't even
1143 .B md/bitmap/chunksize
1144 The bitmap chunksize can only be changed when no bitmap is active, and
1145 the value should be power of 2 and at least 512.
1148 .B md/bitmap/location
1149 This indicates where the write-intent bitmap for the array is stored.
1150 It can be "none" or "file" or a signed offset from the array metadata
1151 - measured in sectors. You cannot set a file by writing here - that can
1152 only be done with the SET_BITMAP_FILE ioctl.
1154 Write 'none' to 'bitmap/location' will clear bitmap, and the previous
1155 location value must be write to it to restore bitmap.
1158 .B md/bitmap/max_backlog_used
1159 This keeps track of the maximum number of concurrent write-behind requests
1160 for an md array, writing any value to this file will clear it.
1163 .B md/bitmap/metadata
1164 This can be 'internal' or 'clustered' or 'external'. 'internal' is set
1165 by default, which means the metadata for bitmap is stored in the first 256
1166 bytes of the bitmap space. 'clustered' means separate bitmap metadata are
1167 used for each cluster node. 'external' means that bitmap metadata is managed
1168 externally to the kernel.
1172 This shows the space (in sectors) which is available at md/bitmap/location,
1173 and allows the kernel to know when it is safe to resize the bitmap to match
1174 a resized array. It should big enough to contain the total bytes in the bitmap.
1176 For 1.0 metadata, assume we can use up to the superblock if before, else
1177 to 4K beyond superblock. For other metadata versions, assume no change is
1181 .B md/bitmap/time_base
1182 This shows the time (in seconds) between disk flushes, and is used to looking
1183 for bits in the bitmap to be cleared.
1185 The default value is 5 seconds, and it should be an unsigned long value.
1187 .SS KERNEL PARAMETERS
1189 The md driver recognised several different kernel parameters.
1191 .B raid=noautodetect
1192 This will disable the normal detection of md arrays that happens at
1193 boot time. If a drive is partitioned with MS-DOS style partitions,
1194 then if any of the 4 main partitions has a partition type of 0xFD,
1195 then that partition will normally be inspected to see if it is part of
1196 an MD array, and if any full arrays are found, they are started. This
1197 kernel parameter disables this behaviour.
1200 .B raid=partitionable
1203 These are available in 2.6 and later kernels only. They indicate that
1204 autodetected MD arrays should be created as partitionable arrays, with
1205 a different major device number to the original non-partitionable md
1206 arrays. The device number is listed as
1212 .B md_mod.start_ro=1
1214 .B /sys/module/md_mod/parameters/start_ro
1215 This tells md to start all arrays in read-only mode. This is a soft
1216 read-only that will automatically switch to read-write on the first
1217 write request. However until that write request, nothing is written
1218 to any device by md, and in particular, no resync or recovery
1219 operation is started.
1222 .B md_mod.start_dirty_degraded=1
1224 .B /sys/module/md_mod/parameters/start_dirty_degraded
1225 As mentioned above, md will not normally start a RAID4, RAID5, or
1226 RAID6 that is both dirty and degraded as this situation can imply
1227 hidden data loss. This can be awkward if the root filesystem is
1228 affected. Using this module parameter allows such arrays to be started
1229 at boot time. It should be understood that there is a real (though
1230 small) risk of data corruption in this situation.
1233 .BI md= n , dev , dev ,...
1235 .BI md=d n , dev , dev ,...
1236 This tells the md driver to assemble
1238 from the listed devices. It is only necessary to start the device
1239 holding the root filesystem this way. Other arrays are best started
1240 once the system is booted.
1244 immediately after the
1246 indicates that a partitionable device (e.g.
1248 should be created rather than the original non-partitionable device.
1251 .BI md= n , l , c , i , dev...
1252 This tells the md driver to assemble a legacy RAID0 or LINEAR array
1253 without a superblock.
1255 gives the md device number,
1257 gives the level, 0 for RAID0 or \-1 for LINEAR,
1259 gives the chunk size as a base-2 logarithm offset by twelve, so 0
1260 means 4K, 1 means 8K.
1262 is ignored (legacy support).
1267 Contains information about the status of currently running array.
1269 .B /proc/sys/dev/raid/speed_limit_min
1270 A readable and writable file that reflects the current "goal" rebuild
1271 speed for times when non-rebuild activity is current on an array.
1272 The speed is in Kibibytes per second, and is a per-device rate, not a
1273 per-array rate (which means that an array with more disks will shuffle
1274 more data for a given speed). The default is 1000.
1277 .B /proc/sys/dev/raid/speed_limit_max
1278 A readable and writable file that reflects the current "goal" rebuild
1279 speed for times when no non-rebuild activity is current on an array.
1280 The default is 200,000.