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.\" 35.\" @(#)vnconfig.8 8.1 (Berkeley) 6/5/93 36.\" from: src/usr.sbin/vnconfig/vnconfig.8,v 1.19 2000/12/27 15:30:29 37.\" 38.\" $FreeBSD$ 39.\" 40.Dd December 21, 2018 41.Dt MDCONFIG 8 42.Os 43.Sh NAME 44.Nm mdconfig 45.Nd create and control memory disks 46.Sh SYNOPSIS 47.Nm 48.Fl a 49.Fl t Ar type 50.Op Fl n 51.Oo Fl o Oo Cm no Oc Ns Ar option Oc ... 52.Op Fl f Ar file 53.Op Fl s Ar size 54.Op Fl S Ar sectorsize 55.Op Fl u Ar unit 56.Op Fl x Ar sectors/track 57.Op Fl y Ar heads/cylinder 58.Op Fl L Ar label 59.Nm 60.Fl d 61.Fl u Ar unit 62.Op Fl o Oo Cm no Oc Ns Ar force 63.Nm 64.Fl r 65.Fl u Ar unit 66.Fl s Ar size 67.Op Fl o Oo Cm no Oc Ns Ar force 68.Nm 69.Fl l 70.Op Fl n 71.Op Fl v 72.Op Fl f Ar file 73.Op Fl u Ar unit 74.Nm 75.Ar file 76.Sh DESCRIPTION 77The 78.Nm 79utility creates and controls 80.Xr md 4 81devices. 82.Pp 83Options indicate an action to be performed: 84.Bl -tag -width indent 85.It Fl a 86Attach a memory disk. 87This will configure and attach a memory disk with the 88parameters specified and attach it to the system. 89If the 90.Fl u Ar unit 91option is not provided, the newly created device name will be printed on stdout. 92.It Fl d 93Detach a memory disk from the system and release all resources. 94.It Fl r 95Resize a memory disk. 96.It Fl t Ar type 97Select the type of the memory disk. 98.Bl -tag -width "malloc" 99.It Cm malloc 100Storage for this type of memory disk is allocated with 101.Xr malloc 9 . 102This limits the size to the malloc bucket limit in the kernel. 103If the 104.Fl o Cm reserve 105option is not set, creating and filling a large 106malloc-backed memory disk is a very easy way to 107panic the system. 108.It Cm vnode 109A file specified with 110.Fl f Ar file 111becomes the backing store for this memory disk. 112.It Cm swap 113Storage for this type of memory disk is allocated from buffer 114memory. 115Pages get pushed out to swap when the system is under memory 116pressure, otherwise they stay in the operating memory. 117Using 118.Cm swap 119backing is generally preferred instead of using 120.Cm malloc 121backing. 122.It Cm null 123Bitsink; all writes do nothing, all reads return zeroes. 124.El 125.It Fl f Ar file 126Filename to use for the vnode type memory disk. 127The 128.Fl a 129and 130.Fl t Ar vnode 131options are implied if not specified. 132.It Fl l 133List configured devices. 134If given with 135.Fl u , 136display details about that particular device. 137If given with 138.Fl f Ar file , 139display 140.Xr md 4 141device names of which 142.Ar file 143is used as the backing store. 144If both of 145.Fl u 146and 147.Fl f 148options are specified, 149display devices which match the two conditions. 150If the 151.Fl v 152option is specified, show all details. 153.It Fl n 154When printing 155.Xr md 4 156device names, print only the unit number without the 157.Xr md 4 158prefix. 159.It Fl s Ar size 160Size of the memory disk. 161.Ar Size 162is the number of 512 byte sectors unless suffixed with a 163.Cm b , k , m , g , t , 164or 165.Cm p 166which 167denotes byte, kilobyte, megabyte, gigabyte, terabyte and petabyte respectively. 168When used without the 169.Fl r 170option, the 171.Fl a 172and 173.Fl t Ar swap 174options are implied if not specified. 175.It Fl S Ar sectorsize 176Sectorsize to use for the memory disk, in bytes. 177.It Fl x Ar sectors/track 178See the description of the 179.Fl y 180option below. 181.It Fl y Ar heads/cylinder 182For 183.Cm malloc 184or 185.Cm vnode 186backed devices, the 187.Fl x 188and 189.Fl y 190options can be used to specify a synthetic geometry. 191This is useful for constructing bootable images for later download to 192other devices. 193.It Fl L Ar label 194Associate a label (arbitrary string) with the new memory disk. 195The label can then be inspected with 196.Bd -literal -offset indent 197.Nm Fl l v 198.Ed 199.It Fl o Oo Cm no Oc Ns Ar option 200Set or reset options. 201.Bl -tag -width indent 202.It Oo Cm no Oc Ns Cm async 203For 204.Cm vnode 205backed devices: avoid 206.Dv IO_SYNC 207for increased performance but 208at the risk of deadlocking the entire kernel. 209.It Oo Cm no Oc Ns Cm cache 210For 211.Cm vnode 212backed devices: enable/disable caching of data in system caches. 213The default is to not cache. 214.Pp 215Accesses via the device are converted to accesses via the vnode. 216The caching policy for the vnode is used initially. 217This is normally to cache. 218This caching policy is retained if the 219.Cm cache 220option is used. 221Otherwise, caching is limited 222by releasing data from caches soon after each access. 223The release has the same semantics as the 224.Dv POSIX_FADV_DONTNEED 225feature of 226.Xr posix_fadvise 2 . 227The result is that with normal (non-zfs) caching, 228buffers are released from the buffer cache soon after they are constructed, 229but their data is kept in the page cache at lower priority. 230.Pp 231The 232.Cm cache 233option tends to waste memory by giving unwanted double caching, 234but it saves time if there is memory to spare. 235.It Oo Cm no Oc Ns Cm reserve 236Allocate and reserve all needed storage from the start, rather than as needed. 237.It Oo Cm no Oc Ns Cm cluster 238Enable clustering on this disk. 239.It Oo Cm no Oc Ns Cm compress 240Enable/disable compression features to reduce memory usage. 241.It Oo Cm no Oc Ns Cm force 242Disable/enable extra sanity checks to prevent the user from doing something 243that might adversely affect the system. 244This can be used with the 245.Fl d 246flag to forcibly destroy an 247.Xr md 4 248disk that is still in use. 249.It Oo Cm no Oc Ns Cm readonly 250Enable/disable readonly mode. 251.It Oo Cm no Oc Ns Cm verify 252For 253.Cm vnode 254backed devices: enable/disable requesting verification of the 255file used for backing store. 256The type of verification depends on which security features are available. 257One example of verification is testing file integrity with 258checksums or cryptographic signatures. 259.El 260.It Fl u Ar unit 261Request a specific unit number or device name for the 262.Xr md 4 263device instead of automatic allocation. 264If a device name is specified, it must be start with 265.Dq md 266followed by the unit number. 267.El 268.Pp 269The last form, 270.Nm 271.Ar file , 272is provided for convenience as an abbreviation of 273.Nm 274.Fl a 275.Fl t Ar vnode 276.Fl f Ar file . 277.Sh EXAMPLES 278Create a disk with 279.Pa /tmp/boot.flp 280as backing storage. 281The name of the allocated unit will be printed on stdout, such as 282.Dq Li md0 : 283.Bd -literal -offset indent 284mdconfig /tmp/boot.flp 285.Ed 286.Pp 287Create a 1 gigabyte swap backed memory disk named 288.Dq Li md3 : 289.Bd -literal -offset indent 290mdconfig -s 1g -u md3 291.Ed 292.Pp 293Detach and free all resources used by 294.Pa /dev/md3 : 295.Bd -literal -offset indent 296mdconfig -du md3 297.Ed 298.Pp 299Show detailed information on current memory disks: 300.Bd -literal -offset indent 301mdconfig -lv 302.Ed 303.Pp 304Resize the 305.Dq Li md3 306memory disk to 2 gigabytes: 307.Bd -literal -offset indent 308mdconfig -rs 2g -u md3 309.Ed 310.Pp 311Create a 1 gigabyte swap backed disk, initialize an 312.Xr ffs 7 313file system on it, and mount it on 314.Pa /tmp : 315.Bd -literal -offset indent 316mdconfig -s 1g -u md10 317newfs -U /dev/md10 318mount /dev/md10 /tmp 319chmod 1777 /tmp 320.Ed 321.Pp 322Create a memory disk out of an ISO 9660 CD image file, 323using the first available 324.Xr md 4 325device, and then mount it: 326.Bd -literal -offset indent 327mount -t cd9660 /dev/`mdconfig -f cdimage.iso` /mnt 328.Ed 329.Pp 330Create a file-backed device from a hard disk image that begins 331with 512K of raw header information. 332.Xr gnop 8 333is used to skip over the header information, positioning 334.Pa md1.nop 335to the start of the filesystem in the image. 336.Bd -literal -offset indent 337mdconfig -u md1 -f diskimage.img 338gnop create -o 512K md1 339mount /dev/md1.nop /mnt 340.Ed 341.Sh SEE ALSO 342.Xr open 2 , 343.Xr md 4 , 344.Xr ffs 7 , 345.Xr gpart 8 , 346.Xr mdmfs 8 , 347.Xr malloc 9 348.Sh HISTORY 349The 350.Nm 351utility first appeared in 352.Fx 5.0 353as a cleaner replacement for the 354.Xr vn 4 355and 356.Xr vnconfig 8 357combo. 358.Sh AUTHORS 359The 360.Nm 361utility was written by 362.An Poul-Henning Kamp Aq Mt phk@FreeBSD.org . 363