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