xref: /freebsd/sbin/mdconfig/mdconfig.8 (revision 7899f917b1c0ea178f1d2be0cfb452086d079d23)
1.\" Copyright (c) 1993 University of Utah.
2.\" Copyright (c) 1980, 1989, 1991, 1993
3.\"	The Regents of the University of California.  All rights reserved.
4.\" Copyright (c) 2000
5.\"	Poul-Henning Kamp  All rights reserved.
6.\"
7.\" This code is derived from software contributed to Berkeley by
8.\" the Systems Programming Group of the University of Utah Computer
9.\" Science Department.
10.\"
11.\" Redistribution and use in source and binary forms, with or without
12.\" modification, are permitted provided that the following conditions
13.\" are met:
14.\" 1. Redistributions of source code must retain the above copyright
15.\"    notice, this list of conditions and the following disclaimer.
16.\" 2. Redistributions in binary form must reproduce the above copyright
17.\"    notice, this list of conditions and the following disclaimer in the
18.\"    documentation and/or other materials provided with the distribution.
19.\" 3. Neither the name of the University nor the names of its contributors
20.\"    may be used to endorse or promote products derived from this software
21.\"    without specific prior written permission.
22.\"
23.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33.\" SUCH DAMAGE.
34.\" from: src/usr.sbin/vnconfig/vnconfig.8,v 1.19 2000/12/27 15:30:29
35.\"
36.Dd June 1, 2024
37.Dt MDCONFIG 8
38.Os
39.Sh NAME
40.Nm mdconfig
41.Nd create and control memory disks
42.Sh SYNOPSIS
43.Nm
44.Fl a
45.Fl t Ar type
46.Op Fl n
47.Oo Fl o Oo Cm no Oc Ns Ar option Oc ...
48.Op Fl f Ar file
49.Op Fl s Ar size
50.Op Fl S Ar sectorsize
51.Op Fl u Ar unit
52.Op Fl x Ar sectors/track
53.Op Fl y Ar heads/cylinder
54.Op Fl L Ar label
55.Nm
56.Fl d
57.Fl u Ar unit
58.Op Fl o Oo Cm no Oc Ns Ar force
59.Nm
60.Fl r
61.Fl u Ar unit
62.Fl s Ar size
63.Op Fl o Oo Cm no Oc Ns Ar force
64.Nm
65.Fl l
66.Op Fl n
67.Op Fl v
68.Op Fl f Ar file
69.Op Fl u Ar unit
70.Nm
71.Ar file
72.Sh DESCRIPTION
73The
74.Nm
75utility creates and controls
76.Xr md 4
77devices.
78.Pp
79Options indicate an action to be performed:
80.Bl -tag -width indent
81.It Fl a
82Attach a memory disk.
83This will configure and attach a memory disk with the
84parameters specified and attach it to the system.
85If the
86.Fl u Ar unit
87option is not provided, the newly created device name will be printed on stdout.
88.It Fl d
89Detach a memory disk from the system and release all resources.
90.It Fl r
91Resize a memory disk.
92.It Fl t Ar type
93Select the type of the memory disk.
94.Bl -tag -width "malloc"
95.It Cm malloc
96Storage for this type of memory disk is allocated with
97.Xr malloc 9 .
98This limits the size to the malloc bucket limit in the kernel.
99If the
100.Fl o Cm reserve
101option is not set, creating and filling a large
102malloc-backed memory disk is a very easy way to
103panic the system.
104.It Cm vnode
105A file specified with
106.Fl f Ar file
107becomes the backing store for this memory disk.
108.It Cm swap
109Storage for this type of memory disk is allocated from buffer
110memory.
111Pages get pushed out to swap when the system is under memory
112pressure, otherwise they stay in the operating memory.
113Using
114.Cm swap
115backing is generally preferred instead of using
116.Cm malloc
117backing.
118.It Cm null
119Bitsink; all writes do nothing, all reads return zeroes.
120.El
121.It Fl f Ar file
122Filename to use for the vnode type memory disk.
123The
124.Fl a
125and
126.Fl t Cm vnode
127options are implied if not specified.
128.It Fl l
129List configured devices.
130If given with
131.Fl u ,
132display details about that particular device.
133If given with
134.Fl f Ar file ,
135display
136.Xr md 4
137device names of which
138.Ar file
139is used as the backing store.
140If both of
141.Fl u
142and
143.Fl f
144options are specified,
145display devices which match the two conditions.
146If the
147.Fl v
148option is specified, show all details.
149.It Fl n
150When printing
151.Xr md 4
152device names, print only the unit number without the
153.Xr md 4
154prefix.
155.It Fl s Ar size
156Size of the memory disk.
157.Ar Size
158is the number of 512 byte sectors unless suffixed with a
159.Cm b , k , m , g , t ,
160or
161.Cm p
162which
163denotes byte, kilobyte, megabyte, gigabyte, terabyte and petabyte respectively.
164When used without the
165.Fl r
166option, the
167.Fl a
168and
169.Fl t Cm swap
170options are implied if not specified.
171.It Fl S Ar sectorsize
172Sectorsize to use for the memory disk, in bytes.
173.It Fl x Ar sectors/track
174See the description of the
175.Fl y
176option below.
177.It Fl y Ar heads/cylinder
178For
179.Cm malloc
180or
181.Cm vnode
182backed devices, the
183.Fl x
184and
185.Fl y
186options can be used to specify a synthetic geometry.
187This is useful for constructing bootable images for later download to
188other devices.
189.It Fl L Ar label
190Associate a label (arbitrary string) with the new memory disk.
191The label can then be inspected with
192.Bd -literal -offset indent
193.Nm Fl l v
194.Ed
195.It Fl o Oo Cm no Oc Ns Ar option
196Set or reset options.
197.Bl -tag -width indent
198.It Oo Cm no Oc Ns Cm async
199For
200.Cm vnode
201backed devices: avoid
202.Dv IO_SYNC
203for increased performance but
204at the risk of deadlocking the entire kernel.
205.It Oo Cm no Oc Ns Cm cache
206For
207.Cm vnode
208backed devices: enable/disable caching of data in system caches.
209The default is to not cache.
210.Pp
211Accesses via the device are converted to accesses via the vnode.
212The caching policy for the vnode is used initially.
213This is normally to cache.
214This caching policy is retained if the
215.Cm cache
216option is used.
217Otherwise, caching is limited
218by releasing data from caches soon after each access.
219The release has the same semantics as the
220.Dv POSIX_FADV_DONTNEED
221feature of
222.Xr posix_fadvise 2 .
223The result is that with normal (non-zfs) caching,
224buffers are released from the buffer cache soon after they are constructed,
225but their data is kept in the page cache at lower priority.
226.Pp
227The
228.Cm cache
229option tends to waste memory by giving unwanted double caching,
230but it saves time if there is memory to spare.
231.It Oo Cm no Oc Ns Cm reserve
232Allocate and reserve all needed storage from the start, rather than as needed.
233.It Oo Cm no Oc Ns Cm compress
234Enable/disable compression features to reduce memory usage.
235.It Oo Cm no Oc Ns Cm force
236Disable/enable extra sanity checks to prevent the user from doing something
237that might adversely affect the system.
238This can be used with the
239.Fl d
240flag to forcibly destroy an
241.Xr md 4
242disk that is still in use.
243.It Oo Cm no Oc Ns Cm mustdealloc
244For
245.Cm vnode
246backed devices: detect whether hole-punching is supported by the underlying file
247system.
248If the file system supports hole-punching, then to handle a
249.Dv BIO_DELETE
250request, some or all of the request's operation range may be turned into a hole
251in the file used for backing store.
252Any parts which are not turned into holes are zero-filled in
253the file.
254If the file system does not support
255hole-punching,
256.Dv BIO_DELETE
257requests to the device are not handled and will fail with
258.Er EOPNOTSUPP .
259.Pp
260When
261.Cm mustdealloc
262is not specified or
263.Oo Cm no Oc Ns Cm mustdealloc
264is specified, for a
265.Dv BIO_DELETE
266request, if the file system supports hole-punching, some or all of the request's
267operation range may be turned into a hole in the file used for backing store.
268Any parts which are not turned into holes are zero-filled in the file.
269If the file system of the vnode type memory disk does not support hole-punching,
270the request's operation range is zero-filled in the file.
271.It Oo Cm no Oc Ns Cm readonly
272Enable/disable readonly mode.
273.It Oo Cm no Oc Ns Cm verify
274For
275.Cm vnode
276backed devices: enable/disable requesting verification of the
277file used for backing store.
278The type of verification depends on which security features are available.
279One example of verification is testing file integrity with
280checksums or cryptographic signatures.
281.El
282.It Fl u Ar unit
283Request a specific unit number or device name for the
284.Xr md 4
285device instead of automatic allocation.
286If a device name is specified, it must start with
287.Dq md
288followed by the unit number.
289.El
290.Pp
291The last form,
292.Nm
293.Ar file ,
294is provided for convenience as an abbreviation of
295.Nm
296.Fl a
297.Fl t Cm vnode
298.Fl f Ar file .
299.Sh EXAMPLES
300Create a disk with
301.Pa /tmp/boot.flp
302as backing storage.
303The name of the allocated unit will be printed on stdout, such as
304.Dq Li md0 :
305.Bd -literal -offset indent
306mdconfig /tmp/boot.flp
307.Ed
308.Pp
309Create a 1 gigabyte swap backed memory disk named
310.Dq Li md3 :
311.Bd -literal -offset indent
312mdconfig -s 1g -u md3
313.Ed
314.Pp
315Detach and free all resources used by
316.Pa /dev/md3 :
317.Bd -literal -offset indent
318mdconfig -du md3
319.Ed
320.Pp
321Show detailed information on current memory disks:
322.Bd -literal -offset indent
323mdconfig -lv
324.Ed
325.Pp
326Resize the
327.Dq Li md3
328memory disk to 2 gigabytes:
329.Bd -literal -offset indent
330mdconfig -rs 2g -u md3
331.Ed
332.Pp
333Create a 1 gigabyte swap backed disk, initialize an
334.Xr ffs 4
335file system on it, and mount it on
336.Pa /tmp :
337.Bd -literal -offset indent
338mdconfig -s 1g -u md10
339newfs -U /dev/md10
340mount /dev/md10 /tmp
341chmod 1777 /tmp
342.Ed
343.Pp
344Create a memory disk out of an ISO 9660 CD image file,
345using the first available
346.Xr md 4
347device, and then mount it:
348.Bd -literal -offset indent
349mount -t cd9660 /dev/`mdconfig -f cdimage.iso` /mnt
350.Ed
351.Pp
352Create a file-backed device from a hard disk image that begins
353with 512K of raw header information.
354.Xr gnop 8
355is used to skip over the header information, positioning
356.Pa md1.nop
357to the start of the filesystem in the image.
358.Bd -literal -offset indent
359mdconfig -u md1 -f diskimage.img
360gnop create -o 512K md1
361mount /dev/md1.nop /mnt
362.Ed
363.Sh SEE ALSO
364.Xr fpathconf 2 ,
365.Xr fspacectl 2 ,
366.Xr open 2 ,
367.Xr ffs 4 ,
368.Xr md 4 ,
369.Xr gpart 8 ,
370.Xr mdmfs 8 ,
371.Xr malloc 9 ,
372.Xr vn_deallocate 9
373.Sh HISTORY
374The
375.Nm
376utility first appeared in
377.Fx 5.0
378as a cleaner replacement for the vn kernel module
379and the vnconfig utility combo.
380.Sh AUTHORS
381The
382.Nm
383utility was written by
384.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org .
385