xref: /freebsd/lib/geom/union/gunion.8 (revision 2e3507c25e42292b45a5482e116d278f5515d04d)
1.\"
2.\" Copyright (c) 2022 Marshall Kirk McKusick <mckusick@mckusick.com>
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 January 19, 2022
26.Dt GUNION 8
27.Os
28.Sh NAME
29.Nm gunion
30.Nd "control utility for UNION GEOM class"
31.Sh SYNOPSIS
32.Nm
33.Cm create
34.Op Fl v
35.Op Fl o Ar offset
36.Op Fl s Ar size
37.Op Fl S Ar secsize
38.Op Fl Z Ar gunionname
39.Ar upperdev lowerdev
40.Nm
41.Cm destroy
42.Op Fl fv
43.Ar prov ...
44.Nm
45.Cm reset
46.Op Fl v
47.Ar prov ...
48.Nm
49.Cm revert
50.Op Fl v
51.Ar prov ...
52.Nm
53.Cm commit
54.Op Fl frv
55.Ar prov ...
56.Nm
57.Cm list
58.Nm
59.Cm status
60.Nm
61.Cm load
62.Nm
63.Cm unload
64.Sh DESCRIPTION
65The
66.Nm
67utility is used to track changes to a read-only disk on a writable disk.
68Logically, a writable disk is placed over a read-only disk.
69Write requests are intercepted and stored on the writable disk.
70Read requests are first checked to see if they have been written
71on the top (writable disk) and if found are returned.
72If they have not been written on the top disk,
73then they are read from the lower disk.
74.Pp
75The
76.Nm
77utility can be especially useful if you have a large disk with a
78corrupted filesystem that you are unsure of how to repair.
79You can use
80.Nm
81to place another disk over the corrupted disk and then attempt
82to repair the filesystem.
83If the repair fails, you can revert all the changes in the upper disk
84and be back to the unchanged state of the lower disk thus allowing you
85to try another approach to repairing it.
86If the repair is successful you can request that all the writes recorded
87on the top disk be written to the lower disk.
88.Pp
89Another use of the
90.Nm
91utility is to try out upgrades to your system.
92Place the upper disk over the disk holding your filesystem that
93is to be upgraded and then run the upgrade on it.
94If it works, commit it;
95if it fails, revert the upgrade.
96An example is given below.
97.Pp
98The upper disk must be at least the size of the disk that it covers.
99The union metadata exists only for the
100period of time that the union is instantiated,
101so it is important to commit the updates before destroying the union.
102If the top disk is about 2.5 percent larger for 512 byte sector disks
103(or 0.5 percent larger for 4K sector disks) than the disk that it covers,
104it is posible (thought not currently implemented) to save the union
105metadata between instantiations of the union device.
106.Pp
107If you do not have physical media available to use for the upper layer, the
108.Xr md 4
109disk can be used instead.
110When used in
111.Cm swap
112mode the changes are all held in buffer memory.
113Pages get pushed out to the swap when the system is under memory pressure,
114otherwise they stay in the operating memory.
115If long-term persistance is desired,
116.Cm vnode
117mode can be used in which a regular file is used as backing store.
118The disk space used by the file is based on the amount of data that
119is written to the top device.
120.Pp
121The first argument to
122.Nm
123indicates an action to be performed:
124.Bl -tag -width "destroy"
125.It Cm create
126Set up a union provider on the two given devices.
127The first device given is used as the top device and must be writable.
128The second device given is used as the bottom device and need only be readable.
129The second device may be mounted read-only but it is recommended
130that it be unmounted and accessed only through a mount of the union device.
131If the operation succeeds, the new provider should appear with name
132.Pa /dev/ Ns Ao Ar upperdev Ac Ns - Ns Ao Ar lowerdev Ac Ns Pa .union .
133An alternate name can be specified with the
134.Fl Z
135flag.
136The kernel module
137.Pa geom_union.ko
138will be loaded if it is not loaded already.
139.Pp
140Additional options include:
141.Bl -tag -width "-Z gunionname"
142.It Fl o Ar offset
143Where to begin on the original provider.
144The default is to start at the beginning of the disk (i.e., at offset 0).
145This option may be used to skip over partitioning information stored
146at the beginning of a disk.
147The offset must be a multiple of the sector size.
148.It Fl s Ar size
149Size of the transparent provider.
150The default is to be the same size as the lower disk.
151Any extra space at the end of the upper disk may be used to store
152union metadata.
153.It Fl S Ar secsize
154Sector size of the transparent provider.
155The default is to be the same sector size as the lower disk.
156.It Fl v
157Be more verbose.
158.It Fl Z Ar gunionname
159The name of the new provider.
160The suffix
161.Dq .union
162will be appended to the provider name.
163.El
164.It Cm destroy
165Turn off the given union providers.
166.Pp
167Additional options include:
168.Bl -tag -width "-f"
169.It Fl f
170Force the removal of the specified provider.
171.It Fl v
172Be more verbose.
173.El
174.It Cm revert
175Discard all the changes made in the top layer thus reverting to the
176original state of the lower device.
177The union device may not be mounted or otherwise in use when a
178.Cm revert
179operation is being done.
180.It Cm commit
181Write all the changes made in the top device to the lower device
182thus committing the lower device to have the same data as the union.
183.Pp
184Additional options include:
185.Bl -tag -width "-f"
186.It Fl f
187The
188.Cm commit
189command will not allow the lower device to be mounted
190or otherwise in use while the
191.Cm commit
192operation is being done.
193However, the
194.Fl f
195flag may be specified to allow the lower device to be mounted read-only.
196To prevent a filesystem panic on the mounted lower-device filesystem,
197immediately after the
198.Cm commit
199operation finishes the lower-device filesystem should be unmounted
200and then remounted to update its metadata state.
201If the lower-device filesystem is currently being used as the root
202filesystem then the
203.Fl r
204flag should be specified to reboot the system at the completion of the
205.Cm commit
206operation.
207.It Fl r
208Reboot the system at the completion of the
209.Cm commit
210operation.
211.It Fl v
212Be more verbose.
213.El
214.It Cm reset
215Reset statistics for the given union providers.
216.It Cm list
217See
218.Xr geom 8 .
219.It Cm status
220See
221.Xr geom 8 .
222.It Cm load
223See
224.Xr geom 8 .
225.It Cm unload
226See
227.Xr geom 8 .
228.El
229.Sh EXIT STATUS
230Exit status is 0 on success, and 1 if the command fails.
231.Sh EXAMPLES
232The following example shows how to create and destroy a
233union provider with disks
234.Pa /dev/da0p1
235as the read-only disk on the bottom and
236.Pa /dev/md0
237as the wriable disk on the top.
238.Bd -literal -offset indent
239gunion create -v md0 da0p1
240mount /dev/md0-da0p1.union /mnt
241.Ed
242.Pp
243Proceed to make changes in /mnt filesystem.
244If they are successful and you want to keep them.
245.Bd -literal -offset indent
246umount /mnt
247gunion commit -v md0-da0p1.union
248.Ed
249.Pp
250If they are unsuccessful and you want to roll back.
251.Bd -literal -offset indent
252umount /mnt
253gunion revert -v md0-da0p1.union
254.Ed
255.Pp
256When done eliminate the union.
257.Bd -literal -offset indent
258umount /mnt
259gunion destroy -v md0-da0p1.union
260.Ed
261.Pp
262All uncommitted changes will be discarded when the union is destroyed.
263.Pp
264If you use the name of the full disk, for example
265.Pa da0
266and it is labelled,
267then a union name will appear for the disk as
268.Pa md0-da0.union
269as well as for each partition on the disk as
270.Pa md0-da0p1.union ,
271.Pa md0-da0p2.union ,
272etc.
273A commit operation can be done only on
274.Pa md0-da0.union
275and will commit changes to all the partitions.
276If partition level commits are desired,
277then a union must be created for each partition.
278.Pp
279The traffic statistics for the given
280union providers can be obtained with the
281.Cm list
282command.
283The example below shows the number of bytes written with
284.Xr newfs 8 :
285.Bd -literal -offset indent
286gunion create md0 da0p1
287newfs /dev/md0-da0p1.union
288gunion list
289.Ed
290.Sh SYSCTL VARIABLES
291The following
292.Xr sysctl 8
293variables can be used to control the behavior of the
294.Nm UNION
295GEOM class.
296The default value is shown next to each variable.
297.Bl -tag -width indent
298.It Va kern.geom.union.debug : No 0
299Debug level of the
300.Nm UNION
301GEOM class.
302This can be set to a number between 0 and 4 inclusive.
303If set to 0, no debug information is printed.
304If set to 1, all the verbose messages are logged.
305If set to 2, addition error-related information is logged.
306If set to 3, mapping operations are logged.
307If set to 4, the maximum amount of debug information is printed.
308.El
309.Sh SEE ALSO
310.Xr geom 4 ,
311.Xr geom 8
312.Sh HISTORY
313The
314.Nm
315utility appeared in
316.Fx 14.0 .
317.Sh AUTHORS
318.An Marshall Kirk McKusick Aq Mt mckusick@mckusick.com
319