xref: /freebsd/lib/geom/mirror/gmirror.8 (revision 4b9d605768acabc460aa6dcfe8a1f8db35b16794)
1.\" Copyright (c) 2004-2009 Pawel Jakub Dawidek <pjd@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd October 5, 2022
26.Dt GMIRROR 8
27.Os
28.Sh NAME
29.Nm gmirror
30.Nd "control utility for mirrored devices"
31.Sh SYNOPSIS
32To compile GEOM_MIRROR into your kernel, add the following lines to your
33kernel configuration file:
34.Bd -ragged -offset indent
35.Cd "options GEOM_MIRROR"
36.Ed
37.Pp
38Alternatively, to load the GEOM_MIRROR module at boot time, add the following
39line to your
40.Xr loader.conf 5 :
41.Bd -literal -offset indent
42geom_mirror_load="YES"
43.Ed
44.Pp
45.No Usage of the Nm
46utility:
47.Pp
48.Nm
49.Cm label
50.Op Fl Fhnv
51.Op Fl b Ar balance
52.Op Fl s Ar slice
53.Ar name
54.Ar prov ...
55.Nm
56.Cm clear
57.Op Fl v
58.Ar prov ...
59.Nm
60.Cm create
61.Op Fl Fnv
62.Op Fl b Ar balance
63.Op Fl s Ar slice
64.Ar name
65.Ar prov ...
66.Nm
67.Cm configure
68.Op Fl adfFhnv
69.Op Fl b Ar balance
70.Op Fl s Ar slice
71.Ar name
72.Nm
73.Cm configure
74.Op Fl v
75.Fl p Ar priority
76.Ar name
77.Ar prov
78.Nm
79.Cm rebuild
80.Op Fl v
81.Ar name
82.Ar prov ...
83.Nm
84.Cm resize
85.Op Fl v
86.Op Fl s Ar size
87.Ar name
88.Nm
89.Cm insert
90.Op Fl hiv
91.Op Fl p Ar priority
92.Ar name
93.Ar prov ...
94.Nm
95.Cm remove
96.Op Fl v
97.Ar name
98.Ar prov ...
99.Nm
100.Cm activate
101.Op Fl v
102.Ar name
103.Ar prov ...
104.Nm
105.Cm deactivate
106.Op Fl v
107.Ar name
108.Ar prov ...
109.Nm
110.Cm destroy
111.Op Fl fv
112.Ar name ...
113.Nm
114.Cm forget
115.Op Fl v
116.Ar name ...
117.Nm
118.Cm stop
119.Op Fl fv
120.Ar name ...
121.Nm
122.Cm dump
123.Ar prov ...
124.Nm
125.Cm list
126.Nm
127.Cm status
128.Nm
129.Cm load
130.Nm
131.Cm unload
132.Sh DESCRIPTION
133The
134.Nm
135utility is used for mirror (RAID1) configurations.
136After a mirror's creation, all components are detected and configured
137automatically.
138All operations like failure detection, stale component detection, rebuild
139of stale components, etc.\& are also done automatically.
140The
141.Nm
142utility uses on-disk metadata (stored in the provider's last sector) to store all needed
143information.
144Since the last sector is used for this purpose, it is possible to place a root
145file system on a mirror.
146.Pp
147The first argument to
148.Nm
149indicates an action to be performed:
150.Bl -tag -width ".Cm deactivate"
151.It Cm label
152Create a mirror.
153The order of components is important, because a component's priority is based on its position
154(starting from 0 to 255).
155The component with the biggest priority is used by the
156.Cm prefer
157balance algorithm
158and is also used as a master component when resynchronization is needed,
159e.g.\& after a power failure when the device was open for writing.
160.Pp
161Additional options include:
162.Bl -tag -width ".Fl b Ar balance"
163.It Fl b Ar balance
164Specifies balance algorithm to use, one of:
165.Bl -tag -width ".Cm round-robin"
166.It Cm load
167Read from the component with the lowest load.
168This is the default balance algorithm.
169.It Cm prefer
170Read from the component with the biggest priority.
171.It Cm round-robin
172Use round-robin algorithm when choosing component to read.
173.It Cm split
174Split read requests, which are bigger than or equal to slice size on N pieces,
175where N is the number of active components.
176.El
177.It Fl F
178Do not synchronize after a power failure or system crash.
179Assumes device is in consistent state.
180.It Fl h
181Hardcode providers' names in metadata.
182.It Fl n
183Turn off autosynchronization of stale components.
184.It Fl s Ar slice
185When using the
186.Cm split
187balance algorithm and an I/O READ request is bigger than or equal to this value,
188the I/O request will be split into N pieces, where N is the number of active
189components.
190Defaults to 4096 bytes.
191.El
192.It Cm clear
193Clear metadata on the given providers.
194.It Cm create
195Similar to
196.Cm label ,
197but creates mirror without storing on-disk metadata in last sector.
198This special "manual" operation mode assumes some external control to manage
199mirror detection after reboot, device hot-plug and other external events.
200.It Cm configure
201Configure the given device.
202.Pp
203Additional options include:
204.Bl -tag -width ".Fl p Ar priority"
205.It Fl a
206Turn on autosynchronization of stale components.
207.It Fl b Ar balance
208Specifies balance algorithm to use.
209.It Fl d
210Do not hardcode providers' names in metadata.
211.It Fl f
212Synchronize device after a power failure or system crash.
213.It Fl F
214Do not synchronize after a power failure or system crash.
215Assumes device is in consistent state.
216.It Fl h
217Hardcode providers' names in metadata.
218.It Fl n
219Turn off autosynchronization of stale components.
220.It Fl p Ar priority
221Specifies priority for the given component
222.Ar prov .
223.It Fl s Ar slice
224Specifies slice size for
225.Cm split
226balance algorithm.
227.El
228.It Cm rebuild
229Rebuild the given mirror components forcibly.
230If autosynchronization was not turned off for the given device, this command
231should be unnecessary.
232.It Cm resize
233Change the size of the given mirror.
234.Pp
235Additional options include:
236.Bl -tag -width ".Fl s Ar size"
237.It Fl s Ar size
238New size of the mirror is expressed in logical block numbers.
239This option can be omitted, then it will be automatically calculated to
240maximum available size.
241.El
242.It Cm insert
243Add the given component(s) to the existing mirror.
244.Pp
245Additional options include:
246.Bl -tag -width ".Fl p Ar priority"
247.It Fl h
248Hardcode providers' names in metadata.
249.It Fl i
250Mark component(s) as inactive immediately after insertion.
251.It Fl p Ar priority
252Specifies priority of the given component(s).
253.El
254.It Cm remove
255Remove the given component(s) from the mirror and clear metadata on it.
256.It Cm activate
257Activate the given component(s), which were marked as inactive before.
258.It Cm deactivate
259Mark the given component(s) as inactive, so it will not be automatically
260connected to the mirror.
261.It Cm destroy
262Stop the given mirror and clear metadata on all its components.
263.Pp
264Additional options include:
265.Bl -tag -width ".Fl f"
266.It Fl f
267Stop the given mirror even if it is opened.
268.El
269.It Cm forget
270Forget about components which are not connected.
271This command is useful when a disk has failed and cannot be reconnected, preventing the
272.Cm remove
273command from being used to remove it.
274.It Cm stop
275Stop the given mirror.
276.Pp
277Additional options include:
278.Bl -tag -width ".Fl f"
279.It Fl f
280Stop the given mirror even if it is opened.
281.El
282.It Cm dump
283Dump metadata stored on the given providers.
284.It Cm list
285See
286.Xr geom 8 .
287.It Cm status
288See
289.Xr geom 8 .
290.It Cm load
291See
292.Xr geom 8 .
293.It Cm unload
294See
295.Xr geom 8 .
296.El
297.Pp
298Additional options include:
299.Bl -tag -width ".Fl v"
300.It Fl v
301Be more verbose.
302.El
303.Sh EXIT STATUS
304Exit status is 0 on success, and 1 if the command fails.
305.Sh EXAMPLES
306Use 3 disks to setup a mirror.
307Choose split balance algorithm, split only
308requests which are bigger than or equal to 2kB.
309Create file system,
310mount it, then unmount it and stop device:
311.Bd -literal -offset indent
312gmirror label -v -b split -s 2048 data da0 da1 da2
313newfs /dev/mirror/data
314mount /dev/mirror/data /mnt
315\&...
316umount /mnt
317gmirror stop data
318gmirror unload
319.Ed
320.Pp
321Create a mirror on disk with valid data (note that the last sector of the disk
322will be overwritten).
323Add another disk to this mirror,
324so it will be synchronized with existing disk:
325.Bd -literal -offset indent
326gmirror label -v -b round-robin data da0
327gmirror insert data da1
328.Ed
329.Pp
330Create a mirror, but do not use automatic synchronization feature.
331Add another disk and rebuild it:
332.Bd -literal -offset indent
333gmirror label -v -n -b load data da0 da1
334gmirror insert data da2
335gmirror rebuild data da2
336.Ed
337.Pp
338One disk failed.
339Replace it with a brand new one:
340.Bd -literal -offset indent
341gmirror forget data
342gmirror insert data da1
343.Ed
344.Pp
345Create a mirror, deactivate one component, do the backup and connect it again.
346It will not be resynchronized, if there is no need to do so (there were no writes in
347the meantime):
348.Bd -literal -offset indent
349gmirror label data da0 da1
350gmirror deactivate data da1
351dd if=/dev/da1 of=/backup/data.img bs=1m
352gmirror activate data da1
353.Ed
354.Sh SYSCTL VARIABLES
355The following
356.Xr sysctl 8
357variables can be used to configure behavior for all mirrors.
358.Bl -tag -width indent
359.It Va kern.geom.mirror.debug
360Control the verbosity of kernel logging related to mirrors.
361A value larger than 0 will enable debug logging.
362.It Va kern.geom.mirror.timeout
363The amount of time, in seconds, to wait for all copies of a mirror to
364appear before starting the mirror.
365Disks that appear after the mirror has been started are not automatically
366added to the mirror.
367.It Va kern.geom.mirror.idletime
368The amount of time, in seconds, which must elapse after the last write to
369a mirror before that mirror is marked clean.
370Clean mirrors do not need to be synchronized after a power failure or
371system crash.
372A small value may result in frequent overwrites of the disks' metadata
373sectors, and thus may reduce the longevity of the disks.
374.It Va kern.geom.mirror.disconnect_on_failure
375Determine whether a disk is automatically removed from its mirror when an
376I/O request to that disk fails.
377.It Va kern.geom.mirror.sync_requests
378The number of parallel I/O requests used while synchronizing a mirror.
379This parameter may only be configured as a
380.Xr loader.conf 5
381tunable.
382.It Va kern.geom.mirror.sync_update_period
383The period, in seconds, at which a synchronizing mirror's metadata is
384updated.
385Periodic updates are used to record a synchronization's progress so that
386an interrupted synchronization may be resumed starting at the recorded
387offset, rather than at the beginning.
388A smaller value results in more accurate progress tracking, but also
389increases the number of non-sequential writes to the disk being synchronized.
390If the sysctl value is 0, no updates are performed until the synchronization
391is complete.
392.El
393.Sh NOTES
394Doing kernel dumps to
395.Nm
396providers is possible, but some conditions have to be met.
397First of all, a kernel dump will go only to one component and
398.Nm
399always chooses the component with the highest priority.
400Reading a dump from the mirror on boot will only work if the
401.Cm prefer
402balance algorithm is used (that way
403.Nm
404will read only from the component with the highest priority).
405If you use a different balance algorithm, you should create an
406.Xr rc 8
407script that sets the balance algorithm to
408.Cm prefer ,
409for example with the following command:
410.Bd -literal -offset indent
411gmirror configure -b prefer data
412.Ed
413.Pp
414Make sure that
415.Xr rcorder 8
416schedules the new script before
417.Xr savecore 8 .
418The desired balance algorithm can be restored later on
419by placing the following command in
420.Xr rc.local 8 :
421.Bd -literal -offset indent
422gmirror configure -b round-robin data
423.Ed
424.Pp
425The decision which component to choose for dumping is made when
426.Xr dumpon 8
427is called.
428If on the next boot a component with a higher priority will be available,
429the prefer algorithm will choose to read from it and
430.Xr savecore 8
431will find nothing.
432If on the next boot a component with the highest priority will be synchronized,
433the prefer balance algorithm will read from the next one, thus will find nothing
434there.
435.Sh SEE ALSO
436.Xr geom 4 ,
437.Xr dumpon 8 ,
438.Xr geom 8 ,
439.Xr gvinum 8 ,
440.Xr mount 8 ,
441.Xr newfs 8 ,
442.Xr savecore 8 ,
443.Xr sysctl 8 ,
444.Xr umount 8
445.Sh HISTORY
446The
447.Nm
448utility appeared in
449.Fx 5.3 .
450.Sh AUTHORS
451.An Pawel Jakub Dawidek Aq Mt pjd@FreeBSD.org
452.Sh BUGS
453There should be a way to change a component's priority inside a running mirror.
454.Pp
455There should be a section with an implementation description.
456