xref: /freebsd/sbin/mdconfig/mdconfig.8 (revision 783d3ff6d7fae619db8a7990b8a6387de0c677b5)
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 August 27, 2021
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 cluster
234Enable clustering on this disk.
235.It Oo Cm no Oc Ns Cm compress
236Enable/disable compression features to reduce memory usage.
237.It Oo Cm no Oc Ns Cm force
238Disable/enable extra sanity checks to prevent the user from doing something
239that might adversely affect the system.
240This can be used with the
241.Fl d
242flag to forcibly destroy an
243.Xr md 4
244disk that is still in use.
245.It Oo Cm no Oc Ns Cm mustdealloc
246For
247.Cm vnode
248backed devices: detect whether hole-punching is supported by the underlying file
249system.
250If the file system supports hole-punching, then to handle a
251.Dv BIO_DELETE
252request, some or all of the request's operation range may be turned into a hole
253in the file used for backing store.
254Any parts which are not turned into holes are zero-filled in
255the file.
256If the file system does not support
257hole-punching,
258.Dv BIO_DELETE
259requests to the device are not handled and will fail with
260.Er EOPNOTSUPP .
261.Pp
262When
263.Cm mustdealloc
264is not specified or
265.Oo Cm no Oc Ns Cm mustdealloc
266is specified, for a
267.Dv BIO_DELETE
268request, if the file system supports hole-punching, some or all of the request's
269operation range may be turned into a hole in the file used for backing store.
270Any parts which are not turned into holes are zero-filled in the file.
271If the file system of the vnode type memory disk does not support hole-punching,
272the request's operation range is zero-filled in the file.
273.It Oo Cm no Oc Ns Cm readonly
274Enable/disable readonly mode.
275.It Oo Cm no Oc Ns Cm verify
276For
277.Cm vnode
278backed devices: enable/disable requesting verification of the
279file used for backing store.
280The type of verification depends on which security features are available.
281One example of verification is testing file integrity with
282checksums or cryptographic signatures.
283.El
284.It Fl u Ar unit
285Request a specific unit number or device name for the
286.Xr md 4
287device instead of automatic allocation.
288If a device name is specified, it must start with
289.Dq md
290followed by the unit number.
291.El
292.Pp
293The last form,
294.Nm
295.Ar file ,
296is provided for convenience as an abbreviation of
297.Nm
298.Fl a
299.Fl t Cm vnode
300.Fl f Ar file .
301.Sh EXAMPLES
302Create a disk with
303.Pa /tmp/boot.flp
304as backing storage.
305The name of the allocated unit will be printed on stdout, such as
306.Dq Li md0 :
307.Bd -literal -offset indent
308mdconfig /tmp/boot.flp
309.Ed
310.Pp
311Create a 1 gigabyte swap backed memory disk named
312.Dq Li md3 :
313.Bd -literal -offset indent
314mdconfig -s 1g -u md3
315.Ed
316.Pp
317Detach and free all resources used by
318.Pa /dev/md3 :
319.Bd -literal -offset indent
320mdconfig -du md3
321.Ed
322.Pp
323Show detailed information on current memory disks:
324.Bd -literal -offset indent
325mdconfig -lv
326.Ed
327.Pp
328Resize the
329.Dq Li md3
330memory disk to 2 gigabytes:
331.Bd -literal -offset indent
332mdconfig -rs 2g -u md3
333.Ed
334.Pp
335Create a 1 gigabyte swap backed disk, initialize an
336.Xr ffs 7
337file system on it, and mount it on
338.Pa /tmp :
339.Bd -literal -offset indent
340mdconfig -s 1g -u md10
341newfs -U /dev/md10
342mount /dev/md10 /tmp
343chmod 1777 /tmp
344.Ed
345.Pp
346Create a memory disk out of an ISO 9660 CD image file,
347using the first available
348.Xr md 4
349device, and then mount it:
350.Bd -literal -offset indent
351mount -t cd9660 /dev/`mdconfig -f cdimage.iso` /mnt
352.Ed
353.Pp
354Create a file-backed device from a hard disk image that begins
355with 512K of raw header information.
356.Xr gnop 8
357is used to skip over the header information, positioning
358.Pa md1.nop
359to the start of the filesystem in the image.
360.Bd -literal -offset indent
361mdconfig -u md1 -f diskimage.img
362gnop create -o 512K md1
363mount /dev/md1.nop /mnt
364.Ed
365.Sh SEE ALSO
366.Xr fpathconf 2 ,
367.Xr fspacectl 2 ,
368.Xr open 2 ,
369.Xr md 4 ,
370.Xr ffs 7 ,
371.Xr gpart 8 ,
372.Xr mdmfs 8 ,
373.Xr malloc 9 ,
374.Xr vn_deallocate 9
375.Sh HISTORY
376The
377.Nm
378utility first appeared in
379.Fx 5.0
380as a cleaner replacement for the vn kernel module
381and the vnconfig utility combo.
382.Sh AUTHORS
383The
384.Nm
385utility was written by
386.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org .
387