xref: /freebsd/sbin/newfs/newfs.8 (revision f126890ac5386406dadf7c4cfa9566cbb56537c5)
1.\" Copyright (c) 1983, 1987, 1991, 1993, 1994
2.\"	The Regents of the University of California.  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.\" 3. Neither the name of the University nor the names of its contributors
13.\"    may be used to endorse or promote products derived from this software
14.\"    without specific prior written permission.
15.\"
16.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26.\" SUCH DAMAGE.
27.\"
28.Dd October 21, 2022
29.Dt NEWFS 8
30.Os
31.Sh NAME
32.Nm newfs
33.Nd construct a new UFS1/UFS2 file system
34.Sh SYNOPSIS
35.Nm
36.Op Fl EJNUjlnt
37.Op Fl L Ar volname
38.Op Fl O Ar filesystem-type
39.Op Fl S Ar sector-size
40.Op Fl T Ar disktype
41.Op Fl a Ar maxcontig
42.Op Fl b Ar block-size
43.Op Fl c Ar blocks-per-cylinder-group
44.Op Fl d Ar max-extent-size
45.Op Fl e Ar maxbpg
46.Op Fl f Ar frag-size
47.Op Fl g Ar avgfilesize
48.Op Fl h Ar avgfpdir
49.Op Fl i Ar bytes
50.Op Fl k Ar held-for-metadata-blocks
51.Op Fl m Ar free-space
52.Op Fl o Ar optimization
53.Op Fl p Ar partition
54.Op Fl r Ar reserved
55.Op Fl s Ar size
56.Ar special
57.Sh DESCRIPTION
58The
59.Nm
60utility is used to initialize and clear file systems before first use.
61The
62.Nm
63utility builds a file system on the specified special file.
64(We often refer to the
65.Dq special file
66as the
67.Dq disk ,
68although the special file need not be a physical disk.
69In fact, it need not even be special.)
70Typically the defaults are reasonable, however
71.Nm
72has numerous options to allow the defaults to be selectively overridden.
73.Pp
74The following options define the general layout policies:
75.Bl -tag -width indent
76.It Fl E
77Erase the content of the disk before making the filesystem.
78The reserved area in front of the superblock (for bootcode) will not be erased.
79Erasing is only relevant to flash-memory or thinly provisioned devices.
80Erasing may take a long time.
81If the device does not support BIO_DELETE, the command will fail.
82.It Fl J
83Enable journaling on the new file system via gjournal.
84See
85.Xr gjournal 8
86for details.
87.It Fl L Ar volname
88Add a volume label to the new file system.
89Legal characters are alphanumerics, dashes, and underscores.
90.It Fl N
91Cause the file system parameters to be printed out
92without really creating the file system.
93.It Fl O Ar filesystem-type
94Use 1 to specify that a UFS1 format file system be built;
95use 2 to specify that a UFS2 format file system be built.
96The default format is UFS2.
97.It Fl T Ar disktype
98For backward compatibility.
99.It Fl U
100Enable soft updates on the new file system.
101.It Fl a Ar maxcontig
102Specify the maximum number of contiguous blocks that will be
103laid out before forcing a rotational delay.
104The default value is 16.
105See
106.Xr tunefs 8
107for more details on how to set this option.
108.It Fl b Ar block-size
109The block size of the file system, in bytes.
110It must be a power of 2.
111.\" If changing the default block size and it causes the default
112.\" fragment size to change, be sure to update the location of
113.\" the first backup superblock on the fsck_ffs.8 manual page.
114The
115default size is 32768 bytes, and the smallest allowable size is 4096 bytes.
116The optimal block:fragment ratio is 8:1.
117Other ratios are possible, but are not recommended,
118and may produce poor results.
119.It Fl c Ar blocks-per-cylinder-group
120The number of blocks per cylinder group in a file system.
121The default is to compute the maximum allowed by the other parameters.
122This value is
123dependent on a number of other parameters, in particular the block size
124and the number of bytes per inode.
125.It Fl d Ar max-extent-size
126The file system may choose to store large files using extents.
127This parameter specifies the largest extent size that may be used.
128The default value is the file system blocksize.
129It is presently limited to a maximum value of 16 times the
130file system blocksize and a minimum value of the file system blocksize.
131.It Fl e Ar maxbpg
132Indicate the maximum number of blocks any single file can
133allocate out of a cylinder group before it is forced to begin
134allocating blocks from another cylinder group.
135The default is about one quarter of the total blocks in a cylinder group.
136See
137.Xr tunefs 8
138for more details on how to set this option.
139.It Fl f Ar frag-size
140The fragment size of the file system in bytes.
141It must be a power of two
142ranging in value between
143.Ar blocksize Ns /8
144and
145.Ar blocksize .
146.\" If changing the default fragment size or it changes because of a
147.\" change to the default block size, be sure to update the location
148.\" of the first backup superblock on the fsck_ffs.8 manual page.
149The default is 4096 bytes.
150.It Fl g Ar avgfilesize
151The expected average file size for the file system.
152.It Fl h Ar avgfpdir
153The expected average number of files per directory on the file system.
154.It Fl i Ar bytes
155Specify the density of inodes in the file system.
156The default is to create an inode for every
157.Pq 2 * Ar frag-size
158bytes of data space.
159If fewer inodes are desired, a larger number should be used;
160to create more inodes a smaller number should be given.
161One inode is required for each distinct file, so this value effectively
162specifies the average file size on the file system.
163.It Fl j
164Enable soft updates journaling on the new file system.
165This flag is implemented by running the
166.Xr tunefs 8
167utility found in the user's
168.Dv $PATH .
169.Pp
170Enabling journaling reduces the time spent by
171.Xr fsck_ffs 8
172cleaning up a filesystem after a crash to a few seconds from minutes to hours.
173Without journaling, the time to recover after a crash is a function
174of the number of files in the filesystem and the size of the filesystem.
175With journaling, the time to recover after a crash is a function of the
176amount of activity in the filesystem in the minute before the crash.
177Journaled recovery time is usually only a few seconds and never
178exceeds a minute.
179.Pp
180The drawback to using journaling is that the writes to its log adds
181an extra write load to the media containing the filesystem.
182Thus a write-intensive workload will have reduced throughput on a
183filesystem running with journaling.
184.Pp
185Like all journaling filesystems, the journal recovery will only fix
186issues known to the journal.
187Specifically if a media error occurs,
188the journal will not know about it and hence will not fix it.
189Thus when using journaling, it is still necessary to run a full fsck
190every few months or after a filesystem panic to check for and fix
191any errors brought on by media failure.
192A full fsck can be done by running a background fsck on a live
193filesystem or by running with the
194.Fl f
195flag on an unmounted filesystem.
196When running
197.Xr fsck_ffs 8
198in background on a live filesystem the filesystem performance
199will be about half of normal during the time that the background
200.Xr fsck_ffs 8
201is running.
202Running a full fsck on a UFS filesystem is the equivalent of
203running a scrub on a ZFS filesystem.
204.It Fl k Ar held-for-metadata-blocks
205Set the amount of space to be held for metadata blocks in each cylinder group.
206When set, the file system preference routines will try to save
207the specified amount of space immediately following the inode blocks
208in each cylinder group for use by metadata blocks.
209Clustering the metadata blocks speeds up random file access
210and decreases the running time of
211.Xr fsck 8 .
212By default
213.Nm
214sets it to half of the space reserved to minfree.
215.It Fl l
216Enable multilabel MAC on the new file system.
217.It Fl m Ar free-space
218The percentage of space reserved from normal users; the minimum free
219space threshold.
220The default value used is
221defined by
222.Dv MINFREE
223from
224.In ufs/ffs/fs.h ,
225currently 8%.
226See
227.Xr tunefs 8
228for more details on how to set this option.
229.It Fl n
230Do not create a
231.Pa .snap
232directory on the new file system.
233The resulting file system will not support snapshot generation, so
234.Xr dump 8
235in live mode and background
236.Xr fsck 8
237will not function properly.
238The traditional
239.Xr fsck 8
240and offline
241.Xr dump 8
242will work on the file system.
243This option is intended primarily for memory or vnode-backed file systems that
244do not require
245.Xr dump 8
246or
247.Xr fsck 8
248support.
249.It Fl o Ar optimization
250.Cm ( space
251or
252.Cm time ) .
253The file system can either be instructed to try to minimize the time spent
254allocating blocks, or to try to minimize the space fragmentation on the disk.
255If the value of minfree (see above) is less than 8%,
256the default is to optimize for
257.Cm space ;
258if the value of minfree is greater than or equal to 8%,
259the default is to optimize for
260.Cm time .
261See
262.Xr tunefs 8
263for more details on how to set this option.
264.It Fl p Ar partition
265The partition name (a..h) you want to use in case the underlying image
266is a file, so you do not have access to individual partitions through the
267filesystem.
268Can also be used with a device, e.g.,
269.Nm
270.Fl p Ar f
271.Ar /dev/da1s3
272is equivalent to
273.Nm
274.Ar /dev/da1s3f .
275.It Fl r Ar reserved
276The size, in sectors, of reserved space
277at the end of the partition specified in
278.Ar special .
279This space will not be occupied by the file system;
280it can be used by other consumers such as
281.Xr geom 4 .
282Defaults to 0.
283.It Fl s Ar size
284The size of the file system in sectors.
285This value defaults to the size of the
286raw partition specified in
287.Ar special
288less the
289.Ar reserved
290space at its end (see
291.Fl r ) .
292A
293.Ar size
294of 0 can also be used to choose the default value.
295A valid
296.Ar size
297value cannot be larger than the default one,
298which means that the file system cannot extend into the reserved space.
299.It Fl t
300Turn on the TRIM enable flag.
301If enabled, and if the underlying device supports the BIO_DELETE
302command, the file system will send a delete request to the underlying
303device for each freed block.
304The trim enable flag is typically set for flash-memory devices to
305reduce write amplification which reduces wear on write-limited
306flash-memory and often improves long-term performance.
307Thinly provisioned storage also benefits by returning unused blocks to
308the global pool.
309.El
310.Pp
311The following options override the standard sizes for the disk geometry.
312Their default values are taken from the disk label.
313Changing these defaults is useful only when using
314.Nm
315to build a file system whose raw image will eventually be used on a
316different type of disk than the one on which it is initially created
317(for example on a write-once disk).
318Note that changing any of these values from their defaults will make
319it impossible for
320.Xr fsck 8
321to find the alternate superblocks if the standard superblock is lost.
322.Bl -tag -width indent
323.It Fl S Ar sector-size
324The size of a sector in bytes (almost never anything but 512).
325.El
326.Sh NOTES ON THE NAMING
327.Dq newfs
328is a common name prefix for utilities creating filesystems, with the suffix
329indicating the type of the filesystem, for instance
330.Xr newfs_msdos 8 .
331The
332.Nm
333utility is a special case which predates that convention.
334.Sh EXAMPLES
335.Dl newfs /dev/ada3s1a
336.Pp
337Creates a new ufs file system on
338.Pa ada3s1a .
339The
340.Nm
341utility will use a block size of 32768 bytes, a fragment size of 4096 bytes
342and the largest possible number of blocks per cylinders group.
343These values tend to produce better performance for most applications
344than the historical defaults
345(8192 byte block size and 1024 byte fragment size).
346This large fragment size may lead to much wasted space
347on file systems that contain many small files.
348.Sh SEE ALSO
349.Xr fdformat 8 ,
350.Xr geom 4 ,
351.Xr disktab 5 ,
352.Xr fs 5 ,
353.Xr camcontrol 8 ,
354.Xr dump 8 ,
355.Xr dumpfs 8 ,
356.Xr fsck 8 ,
357.Xr gjournal 8 ,
358.Xr gpart 8 ,
359.Xr growfs 8 ,
360.Xr gvinum 8 ,
361.Xr makefs 8 ,
362.Xr mount 8 ,
363.Xr newfs_msdos 8 ,
364.Xr tunefs 8
365.Rs
366.%A M. McKusick
367.%A W. Joy
368.%A S. Leffler
369.%A R. Fabry
370.%T A Fast File System for UNIX
371.%J ACM Transactions on Computer Systems 2
372.%V 3
373.%P pp 181-197
374.%D August 1984
375.%O (reprinted in the BSD System Manager's Manual)
376.Re
377.Sh HISTORY
378The
379.Nm
380utility appeared in
381.Bx 4.2 .
382