]> git.ipfire.org Git - thirdparty/mdadm.git/blob - md.4
Document usage of version0.91 superblock.
[thirdparty/mdadm.git] / md.4
1 .TH MD 4
2 .SH NAME
3 md \- Multiple Device driver aka Linux Software Raid
4 .SH SYNOPSIS
5 .BI /dev/md n
6 .br
7 .BI /dev/md/ n
8 .SH DESCRIPTION
9 The
10 .B md
11 driver provides virtual devices that are created from one or more
12 independent underlying devices. This array of devices often contains
13 redundancy, and hence the acronym RAID which stands for a Redundant
14 Array of Independent Devices.
15 .PP
16 .B md
17 supports RAID levels
18 1 (mirroring),
19 4 (striped array with parity device),
20 5 (striped array with distributed parity information),
21 6 (striped array with distributed dual redundancy information), and
22 10 (striped and mirrored).
23 If some number of underlying devices fails while using one of these
24 levels, the array will continue to function; this number is one for
25 RAID levels 4 and 5, two for RAID level 6, and all but one (N-1) for
26 RAID level 1, and dependant on configuration for level 10.
27 .PP
28 .B md
29 also supports a number of pseudo RAID (non-redundant) configurations
30 including RAID0 (striped array), LINEAR (catenated array),
31 MULTIPATH (a set of different interfaces to the same device),
32 and FAULTY (a layer over a single device into which errors can be injected).
33
34 .SS MD SUPER BLOCK
35 Each device in an array may have a
36 .I superblock
37 which records information about the structure and state of the array.
38 This allows the array to be reliably re-assembled after a shutdown.
39
40 From Linux kernel version 2.6.10,
41 .B md
42 provides support for two different formats of this superblock, and
43 other formats can be added. Prior to this release, only one format is
44 supported.
45
46 The common format - known as version 0.90 - has
47 a superblock that is 4K long and is written into a 64K aligned block that
48 starts at least 64K and less than 128K from the end of the device
49 (i.e. to get the address of the superblock round the size of the
50 device down to a multiple of 64K and then subtract 64K).
51 The available size of each device is the amount of space before the
52 super block, so between 64K and 128K is lost when a device in
53 incorporated into an MD array.
54 This superblock stores multi-byte fields in a processor-dependant
55 manner, so arrays cannot easily be moved between computers with
56 different processors.
57
58 The new format - known as version 1 - has a superblock that is
59 normally 1K long, but can be longer. It is normally stored between 8K
60 and 12K from the end of the device, on a 4K boundary, though
61 variations can be stored at the start of the device (version 1.1) or 4K from
62 the start of the device (version 1.2).
63 This superblock format stores multibyte data in a
64 processor-independent format and has supports up to hundreds of
65 component devices (version 0.90 only supports 28).
66
67 The superblock contains, among other things:
68 .TP
69 LEVEL
70 The manner in which the devices are arranged into the array
71 (linear, raid0, raid1, raid4, raid5, raid10, multipath).
72 .TP
73 UUID
74 a 128 bit Universally Unique Identifier that identifies the array that
75 this device is part of.
76
77 When a version 0.90 array is being reshaped (e.g. adding extra devices
78 to a RAID5), the version number is temporarily set to 0.91. This
79 ensures that if the reshape process is stopped in the middle (e.g. by
80 a system crash) and the machine boots into an older kernel that does
81 not support reshaping, then the array will not be assembled (which
82 would cause data corruption) but will be left untouched until a kernel
83 that can complete the reshape processes is used.
84
85 .SS ARRAYS WITHOUT SUPERBLOCKS
86 While it is usually best to create arrays with superblocks so that
87 they can be assembled reliably, there are some circumstances where an
88 array without superblocks in preferred. This include:
89 .TP
90 LEGACY ARRAYS
91 Early versions of the
92 .B md
93 driver only supported Linear and Raid0 configurations and did not use
94 a superblock (which is less critical with these configurations).
95 While such arrays should be rebuilt with superblocks if possible,
96 .B md
97 continues to support them.
98 .TP
99 FAULTY
100 Being a largely transparent layer over a different device, the FAULTY
101 personality doesn't gain anything from having a superblock.
102 .TP
103 MULTIPATH
104 It is often possible to detect devices which are different paths to
105 the same storage directly rather than having a distinctive superblock
106 written to the device and searched for on all paths. In this case,
107 a MULTIPATH array with no superblock makes sense.
108 .TP
109 RAID1
110 In some configurations it might be desired to create a raid1
111 configuration that does use a superblock, and to maintain the state of
112 the array elsewhere. While not encouraged for general us, it does
113 have special-purpose uses and is supported.
114
115 .SS LINEAR
116
117 A linear array simply catenates the available space on each
118 drive together to form one large virtual drive.
119
120 One advantage of this arrangement over the more common RAID0
121 arrangement is that the array may be reconfigured at a later time with
122 an extra drive and so the array is made bigger without disturbing the
123 data that is on the array. However this cannot be done on a live
124 array.
125
126 If a chunksize is given with a LINEAR array, the usable space on each
127 device is rounded down to a multiple of this chunksize.
128
129 .SS RAID0
130
131 A RAID0 array (which has zero redundancy) is also known as a
132 striped array.
133 A RAID0 array is configured at creation with a
134 .B "Chunk Size"
135 which must be a power of two, and at least 4 kibibytes.
136
137 The RAID0 driver assigns the first chunk of the array to the first
138 device, the second chunk to the second device, and so on until all
139 drives have been assigned one chunk. This collection of chunks forms
140 a
141 .BR stripe .
142 Further chunks are gathered into stripes in the same way which are
143 assigned to the remaining space in the drives.
144
145 If devices in the array are not all the same size, then once the
146 smallest device has been exhausted, the RAID0 driver starts
147 collecting chunks into smaller stripes that only span the drives which
148 still have remaining space.
149
150
151 .SS RAID1
152
153 A RAID1 array is also known as a mirrored set (though mirrors tend to
154 provide reflected images, which RAID1 does not) or a plex.
155
156 Once initialised, each device in a RAID1 array contains exactly the
157 same data. Changes are written to all devices in parallel. Data is
158 read from any one device. The driver attempts to distribute read
159 requests across all devices to maximise performance.
160
161 All devices in a RAID1 array should be the same size. If they are
162 not, then only the amount of space available on the smallest device is
163 used. Any extra space on other devices is wasted.
164
165 .SS RAID4
166
167 A RAID4 array is like a RAID0 array with an extra device for storing
168 parity. This device is the last of the active devices in the
169 array. Unlike RAID0, RAID4 also requires that all stripes span all
170 drives, so extra space on devices that are larger than the smallest is
171 wasted.
172
173 When any block in a RAID4 array is modified the parity block for that
174 stripe (i.e. the block in the parity device at the same device offset
175 as the stripe) is also modified so that the parity block always
176 contains the "parity" for the whole stripe. i.e. its contents is
177 equivalent to the result of performing an exclusive-or operation
178 between all the data blocks in the stripe.
179
180 This allows the array to continue to function if one device fails.
181 The data that was on that device can be calculated as needed from the
182 parity block and the other data blocks.
183
184 .SS RAID5
185
186 RAID5 is very similar to RAID4. The difference is that the parity
187 blocks for each stripe, instead of being on a single device, are
188 distributed across all devices. This allows more parallelism when
189 writing as two different block updates will quite possibly affect
190 parity blocks on different devices so there is less contention.
191
192 This also allows more parallelism when reading as read requests are
193 distributed over all the devices in the array instead of all but one.
194
195 .SS RAID6
196
197 RAID6 is similar to RAID5, but can handle the loss of any \fItwo\fP
198 devices without data loss. Accordingly, it requires N+2 drives to
199 store N drives worth of data.
200
201 The performance for RAID6 is slightly lower but comparable to RAID5 in
202 normal mode and single disk failure mode. It is very slow in dual
203 disk failure mode, however.
204
205 .SS RAID10
206
207 RAID10 provides a combination of RAID1 and RAID0, and sometimes known
208 as RAID1+0. Every datablock is duplicated some number of times, and
209 the resulting collection of datablocks are distributed over multiple
210 drives.
211
212 When configuring a RAID10 array it is necessary to specify the number
213 of replicas of each data block that are required (this will normally
214 be 2) and whether the replicas should be 'near', 'offset' or 'far'.
215 (Note that the 'offset' layout is only available from 2.6.18).
216
217 When 'near' replicas are chosen, the multiple copies of a given chunk
218 are laid out consecutively across the stripes of the array, so the two
219 copies of a datablock will likely be at the same offset on two
220 adjacent devices.
221
222 When 'far' replicas are chosen, the multiple copies of a given chunk
223 are laid out quite distant from each other. The first copy of all
224 data blocks will be striped across the early part of all drives in
225 RAID0 fashion, and then the next copy of all blocks will be striped
226 across a later section of all drives, always ensuring that all copies
227 of any given block are on different drives.
228
229 The 'far' arrangement can give sequential read performance equal to
230 that of a RAID0 array, but at the cost of degraded write performance.
231
232 When 'offset' replicas are chosen, the multiple copies of a given
233 chunk are laid out on consecutive drives and at consecutive offsets.
234 Effectively each stripe is duplicated and the copies are offset by one
235 device. This should give similar read characteristics to 'far' if a
236 suitably large chunk size is used, but without as much seeking for
237 writes.
238
239 It should be noted that the number of devices in a RAID10 array need
240 not be a multiple of the number of replica of each data block, those
241 there must be at least as many devices as replicas.
242
243 If, for example, an array is created with 5 devices and 2 replicas,
244 then space equivalent to 2.5 of the devices will be available, and
245 every block will be stored on two different devices.
246
247 Finally, it is possible to have an array with both 'near' and 'far'
248 copies. If and array is configured with 2 near copies and 2 far
249 copies, then there will be a total of 4 copies of each block, each on
250 a different drive. This is an artifact of the implementation and is
251 unlikely to be of real value.
252
253 .SS MUTIPATH
254
255 MULTIPATH is not really a RAID at all as there is only one real device
256 in a MULTIPATH md array. However there are multiple access points
257 (paths) to this device, and one of these paths might fail, so there
258 are some similarities.
259
260 A MULTIPATH array is composed of a number of logically different
261 devices, often fibre channel interfaces, that all refer the the same
262 real device. If one of these interfaces fails (e.g. due to cable
263 problems), the multipath driver will attempt to redirect requests to
264 another interface.
265
266 .SS FAULTY
267 The FAULTY md module is provided for testing purposes. A faulty array
268 has exactly one component device and is normally assembled without a
269 superblock, so the md array created provides direct access to all of
270 the data in the component device.
271
272 The FAULTY module may be requested to simulate faults to allow testing
273 of other md levels or of filesystems. Faults can be chosen to trigger
274 on read requests or write requests, and can be transient (a subsequent
275 read/write at the address will probably succeed) or persistent
276 (subsequent read/write of the same address will fail). Further, read
277 faults can be "fixable" meaning that they persist until a write
278 request at the same address.
279
280 Fault types can be requested with a period. In this case the fault
281 will recur repeatedly after the given number of requests of the
282 relevant type. For example if persistent read faults have a period of
283 100, then every 100th read request would generate a fault, and the
284 faulty sector would be recorded so that subsequent reads on that
285 sector would also fail.
286
287 There is a limit to the number of faulty sectors that are remembered.
288 Faults generated after this limit is exhausted are treated as
289 transient.
290
291 The list of faulty sectors can be flushed, and the active list of
292 failure modes can be cleared.
293
294 .SS UNCLEAN SHUTDOWN
295
296 When changes are made to a RAID1, RAID4, RAID5, RAID6, or RAID10 array
297 there is a possibility of inconsistency for short periods of time as
298 each update requires are least two block to be written to different
299 devices, and these writes probably wont happen at exactly the same
300 time. Thus if a system with one of these arrays is shutdown in the
301 middle of a write operation (e.g. due to power failure), the array may
302 not be consistent.
303
304 To handle this situation, the md driver marks an array as "dirty"
305 before writing any data to it, and marks it as "clean" when the array
306 is being disabled, e.g. at shutdown. If the md driver finds an array
307 to be dirty at startup, it proceeds to correct any possibly
308 inconsistency. For RAID1, this involves copying the contents of the
309 first drive onto all other drives. For RAID4, RAID5 and RAID6 this
310 involves recalculating the parity for each stripe and making sure that
311 the parity block has the correct data. For RAID10 it involves copying
312 one of the replicas of each block onto all the others. This process,
313 known as "resynchronising" or "resync" is performed in the background.
314 The array can still be used, though possibly with reduced performance.
315
316 If a RAID4, RAID5 or RAID6 array is degraded (missing at least one
317 drive) when it is restarted after an unclean shutdown, it cannot
318 recalculate parity, and so it is possible that data might be
319 undetectably corrupted. The 2.4 md driver
320 .B does not
321 alert the operator to this condition. The 2.6 md driver will fail to
322 start an array in this condition without manual intervention, though
323 this behaviour can be over-ridden by a kernel parameter.
324
325 .SS RECOVERY
326
327 If the md driver detects a write error on a device in a RAID1, RAID4,
328 RAID5, RAID6, or RAID10 array, it immediately disables that device
329 (marking it as faulty) and continues operation on the remaining
330 devices. If there is a spare drive, the driver will start recreating
331 on one of the spare drives the data what was on that failed drive,
332 either by copying a working drive in a RAID1 configuration, or by
333 doing calculations with the parity block on RAID4, RAID5 or RAID6, or
334 by finding a copying originals for RAID10.
335
336 In kernels prior to about 2.6.15, a read error would cause the same
337 effect as a write error. In later kernels, a read-error will instead
338 cause md to attempt a recovery by overwriting the bad block. i.e. it
339 will find the correct data from elsewhere, write it over the block
340 that failed, and then try to read it back again. If either the write
341 or the re-read fail, md will treat the error the same way that a write
342 error is treated and will fail the whole device.
343
344 While this recovery process is happening, the md driver will monitor
345 accesses to the array and will slow down the rate of recovery if other
346 activity is happening, so that normal access to the array will not be
347 unduly affected. When no other activity is happening, the recovery
348 process proceeds at full speed. The actual speed targets for the two
349 different situations can be controlled by the
350 .B speed_limit_min
351 and
352 .B speed_limit_max
353 control files mentioned below.
354
355 .SS BITMAP WRITE-INTENT LOGGING
356
357 From Linux 2.6.13,
358 .I md
359 supports a bitmap based write-intent log. If configured, the bitmap
360 is used to record which blocks of the array may be out of sync.
361 Before any write request is honoured, md will make sure that the
362 corresponding bit in the log is set. After a period of time with no
363 writes to an area of the array, the corresponding bit will be cleared.
364
365 This bitmap is used for two optimisations.
366
367 Firstly, after an unclear shutdown, the resync process will consult
368 the bitmap and only resync those blocks that correspond to bits in the
369 bitmap that are set. This can dramatically increase resync time.
370
371 Secondly, when a drive fails and is removed from the array, md stops
372 clearing bits in the intent log. If that same drive is re-added to
373 the array, md will notice and will only recover the sections of the
374 drive that are covered by bits in the intent log that are set. This
375 can allow a device to be temporarily removed and reinserted without
376 causing an enormous recovery cost.
377
378 The intent log can be stored in a file on a separate device, or it can
379 be stored near the superblocks of an array which has superblocks.
380
381 It is possible to add an intent log or an active array, or remove an
382 intent log if one is present.
383
384 In 2.6.13, intent bitmaps are only supported with RAID1. Other levels
385 with redundancy are supported from 2.6.15.
386
387 .SS WRITE-BEHIND
388
389 From Linux 2.6.14,
390 .I md
391 supports WRITE-BEHIND on RAID1 arrays.
392
393 This allows certain devices in the array to be flagged as
394 .IR write-mostly .
395 MD will only read from such devices if there is no
396 other option.
397
398 If a write-intent bitmap is also provided, write requests to
399 write-mostly devices will be treated as write-behind requests and md
400 will not wait for writes to those requests to complete before
401 reporting the write as complete to the filesystem.
402
403 This allows for a RAID1 with WRITE-BEHIND to be used to mirror data
404 over a slow link to a remove computer (providing the link isn't too
405 slow). The extra latency of the remote link will not slow down normal
406 operations, but the remote system will still have a reasonably
407 up-to-date copy of all data.
408
409 .SS RESTRIPING
410
411 .IR Restriping ,
412 also known as
413 .IR Reshaping ,
414 is the processes of re-arranging the data stored in each stripe into a
415 new layout. This might involve changing the number of devices in the
416 array (so the stripes are wider) changing the chunk size (so stripes
417 are deeper or shallower), or changing the arrangement of data and
418 parity, possibly changing the raid level (e.g. 1 to 5 or 5 to 6).
419
420 As of Linux 2.6.17, md can reshape a raid5 array to have more
421 devices. Other possibilities may follow in future kernels.
422
423 During any stripe process there is a 'critical section' during which
424 live data is being over-written on disk. For the operation of
425 increasing the number of drives in a raid5, this critical section
426 covers the first few stripes (the number being the product of the old
427 and new number of devices). After this critical section is passed,
428 data is only written to areas of the array which no longer hold live
429 data - the live data has already been located away.
430
431 md is not able to ensure data preservation if there is a crash
432 (e.g. power failure) during the critical section. If md is asked to
433 start an array which failed during a critical section of restriping,
434 it will fail to start the array.
435
436 To deal with this possibility, a user-space program must
437 .IP \(bu 4
438 Disable writes to that section of the array (using the
439 .B sysfs
440 interface),
441 .IP \(bu 4
442 Take a copy of the data somewhere (i.e. make a backup)
443 .IP \(bu 4
444 Allow the process to continue and invalidate the backup and restore
445 write access once the critical section is passed, and
446 .IP \(bu 4
447 Provide for restoring the critical data before restarting the array
448 after a system crash.
449 .PP
450
451 .B mdadm
452 version 2.4 and later will do this for growing a RAID5 array.
453
454 For operations that do not change the size of the array, like simply
455 increasing chunk size, or converting RAID5 to RAID6 with one extra
456 device, the entire process is the critical section. In this case the
457 restripe will need to progress in stages as a section is suspended,
458 backed up,
459 restriped, and released. This is not yet implemented.
460
461 .SS SYSFS INTERFACE
462 All block devices appear as a directory in
463 .I sysfs
464 (usually mounted at
465 .BR /sys ).
466 For MD devices, this directory will contain a subdirectory called
467 .B md
468 which contains various files for providing access to information about
469 the array.
470
471 This interface is documented more fully in the file
472 .B Documentation/md.txt
473 which is distributed with the kernel sources. That file should be
474 consulted for full documentation. The following are just a selection
475 of attribute files that are available.
476
477 .TP
478 .B md/sync_speed_min
479 This value, if set, overrides the system-wide setting in
480 .B /proc/sys/dev/raid/speed_limit_min
481 for this array only.
482 Writing the value
483 .B system
484 to this file cause the system-wide setting to have effect.
485
486 .TP
487 .B md/sync_speed_max
488 This is the partner of
489 .B md/sync_speed_min
490 and overrides
491 .B /proc/sys/dev/raid/spool_limit_max
492 described below.
493
494 .TP
495 .B md/sync_action
496 This can be used to monitor and control the resync/recovery process of
497 MD.
498 In particular, writing "check" here will cause the array to read all
499 data block and check that they are consistent (e.g. parity is correct,
500 or all mirror replicas are the same). Any discrepancies found are
501 .B NOT
502 corrected.
503
504 A count of problems found will be stored in
505 .BR md/mismatch_count .
506
507 Alternately, "repair" can be written which will cause the same check
508 to be performed, but any errors will be corrected.
509
510 Finally, "idle" can be written to stop the check/repair process.
511
512 .TP
513 .B md/stripe_cache_size
514 This is only available on RAID5 and RAID6. It records the size (in
515 pages per device) of the stripe cache which is used for synchronising
516 all read and write operations to the array. The default is 128.
517 Increasing this number can increase performance in some situations, at
518 some cost in system memory.
519
520
521 .SS KERNEL PARAMETERS
522
523 The md driver recognised several different kernel parameters.
524 .TP
525 .B raid=noautodetect
526 This will disable the normal detection of md arrays that happens at
527 boot time. If a drive is partitioned with MS-DOS style partitions,
528 then if any of the 4 main partitions has a partition type of 0xFD,
529 then that partition will normally be inspected to see if it is part of
530 an MD array, and if any full arrays are found, they are started. This
531 kernel parameter disables this behaviour.
532
533 .TP
534 .B raid=partitionable
535 .TP
536 .B raid=part
537 These are available in 2.6 and later kernels only. They indicate that
538 autodetected MD arrays should be created as partitionable arrays, with
539 a different major device number to the original non-partitionable md
540 arrays. The device number is listed as
541 .I mdp
542 in
543 .IR /proc/devices .
544
545 .TP
546 .B md_mod.start_ro=1
547 This tells md to start all arrays in read-only mode. This is a soft
548 read-only that will automatically switch to read-write on the first
549 write request. However until that write request, nothing is written
550 to any device by md, and in particular, no resync or recovery
551 operation is started.
552
553 .TP
554 .B md_mod.start_dirty_degraded=1
555 As mentioned above, md will not normally start a RAID4, RAID5, or
556 RAID6 that is both dirty and degraded as this situation can imply
557 hidden data loss. This can be awkward if the root filesystem is
558 affected. Using the module parameter allows such arrays to be started
559 at boot time. It should be understood that there is a real (though
560 small) risk of data corruption in this situation.
561
562 .TP
563 .BI md= n , dev , dev ,...
564 .TP
565 .BI md=d n , dev , dev ,...
566 This tells the md driver to assemble
567 .B /dev/md n
568 from the listed devices. It is only necessary to start the device
569 holding the root filesystem this way. Other arrays are best started
570 once the system is booted.
571
572 In 2.6 kernels, the
573 .B d
574 immediately after the
575 .B =
576 indicates that a partitionable device (e.g.
577 .BR /dev/md/d0 )
578 should be created rather than the original non-partitionable device.
579
580 .TP
581 .BI md= n , l , c , i , dev...
582 This tells the md driver to assemble a legacy RAID0 or LINEAR array
583 without a superblock.
584 .I n
585 gives the md device number,
586 .I l
587 gives the level, 0 for RAID0 or -1 for LINEAR,
588 .I c
589 gives the chunk size as a base-2 logarithm offset by twelve, so 0
590 means 4K, 1 means 8K.
591 .I i
592 is ignored (legacy support).
593
594 .SH FILES
595 .TP
596 .B /proc/mdstat
597 Contains information about the status of currently running array.
598 .TP
599 .B /proc/sys/dev/raid/speed_limit_min
600 A readable and writable file that reflects the current goal rebuild
601 speed for times when non-rebuild activity is current on an array.
602 The speed is in Kibibytes per second, and is a per-device rate, not a
603 per-array rate (which means that an array with more disc will shuffle
604 more data for a given speed). The default is 100.
605
606 .TP
607 .B /proc/sys/dev/raid/speed_limit_max
608 A readable and writable file that reflects the current goal rebuild
609 speed for times when no non-rebuild activity is current on an array.
610 The default is 100,000.
611
612 .SH SEE ALSO
613 .BR mdadm (8),
614 .BR mkraid (8).