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