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