1.\" $NetBSD: newfs_ext2fs.8,v 1.15 2023/05/17 09:54:59 tsutsui Exp $ 2.\" 3.\" Copyright (c) 1983, 1987, 1991, 1993, 1994 4.\" The Regents of the University of California. All rights reserved. 5.\" 6.\" Redistribution and use in source and binary forms, with or without 7.\" modification, are permitted provided that the following conditions 8.\" are met: 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 2. Redistributions in binary form must reproduce the above copyright 12.\" notice, this list of conditions and the following disclaimer in the 13.\" documentation and/or other materials provided with the distribution. 14.\" 3. Neither the name of the University nor the names of its contributors 15.\" may be used to endorse or promote products derived from this software 16.\" without specific prior written permission. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 19.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 21.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 22.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 24.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 25.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28.\" SUCH DAMAGE. 29.\" 30.\" @(#)newfs.8 8.6 (Berkeley) 5/3/95 31.\" 32.Dd April 13, 2019 33.Dt NEWFS_EXT2FS 8 34.Os 35.Sh NAME 36.Nm newfs_ext2fs 37.Nd construct a new ext2 file system 38.Sh SYNOPSIS 39.Nm 40.Op Fl FINZ 41.Op Fl b Ar block-size 42.Op Fl D Ar inodesize 43.Op Fl f Ar frag-size 44.Op Fl i Ar bytes-per-inode 45.Op Fl m Ar free-space 46.Op Fl n Ar inodes 47.Op Fl O Ar filesystem-format 48.Op Fl S Ar sector-size 49.Op Fl s Ar size 50.Op Fl V Ar verbose 51.Op Fl v Ar volname 52.Ar special 53.Sh DESCRIPTION 54.Nm 55is used to initialize and clear ext2 file systems before first use. 56Before running 57.Nm 58the disk must be labeled using 59.Xr disklabel 8 . 60.Nm 61builds a file system on the specified special device 62basing its defaults on the information in the disk label. 63Typically the defaults are reasonable, however 64.Nm 65has numerous options to allow the defaults to be selectively overridden. 66.Pp 67Options with numeric arguments may contain an optional (case-insensitive) 68suffix: 69.Bl -tag -width 3n -offset indent -compact 70.It b 71Bytes; causes no modification. 72(Default) 73.It k 74Kilo; multiply the argument by 1024. 75.It m 76Mega; multiply the argument by 1048576. 77.It g 78Giga; multiply the argument by 1073741824. 79.El 80.Pp 81The following options define the general layout policies. 82.Bl -tag -width Fl 83.It Fl b Ar block-size 84The block size of the file system, in bytes. 85It must be a power of two. 86The smallest allowable size is 1024 bytes. 87The default size depends upon the size of the file system: 88.Pp 89.Bl -tag -width "file system size" -compact -offset indent 90.It Sy "file system size" 91.Ar block-size 92.It <= 512 MB 931 KB 94.It > 512 MB 954 KB 96.El 97.It Fl D Ar inodesize 98Set the inode size. 99Defaults to 128, and can also be set to 256 for 100compatibility with ext4. 101.It Fl F 102Create a file system image in 103.Ar special . 104The file system size needs to be specified with 105.Dq Fl s Ar size . 106No attempts to use or update the disk label will be made. 107.It Fl f Ar frag-size 108The fragment size of the file system in bytes. 109It must be the same with blocksize because the current ext2fs 110implementation doesn't support fragmentation. 111.It Fl I 112Do not require that the file system type listed in the disk label is 113.Ql Linux\ Ext2 . 114.It Fl i Ar bytes-per-inode 115This specifies the density of inodes in the file system. 116If fewer inodes are desired, a larger number should be used; 117to create more inodes a smaller number should be given. 118.It Fl m Ar free-space 119The percentage of space reserved from normal users; the minimum free 120space threshold. 121The default value used is 5%. 122.It Fl N 123Causes the file system parameters to be printed out 124without really creating the file system. 125.It Fl n Ar inodes 126This specifies the number of inodes for the file system. 127If both 128.Fl i 129and 130.Fl n 131are specified then 132.Fl n 133takes precedence. 134The default number of inodes is calculated from a number of blocks in 135the file system. 136.It Fl O Ar filesystem-format 137Select the filesystem-format. 138.Bl -tag -width 3n -offset indent -compact 139.It 0 140.Ql GOOD_OLD_REV ; 141this option is primarily used to build root file systems that can be 142understood by old or dumb firmwares for bootstrap. 143.It 1 144.Ql DYNAMIC_REV ; 145the default. 146Various extended (and sometimes incompatible) features are enabled 147(though not all features are supported on 148.Nx ) . 149Currently only the following features are supported: 150.Bl -tag -width "SPARSESUPER" -offset indent -compact 151.It RESIZE 152Prepare some reserved structures which enable future file system resizing. 153.It FTYPE 154Store file types in directory entries to improve performance. 155.It SPARSESUPER 156Prepare superblock backups for the 157.Xr fsck_ext2fs 8 158utility on not all but sparse block groups. 159.It LARGEFILE 160Enable files larger than 2G bytes. 161.El 162.El 163.It Fl s Ar size 164The size of the file system in sectors. 165An 166.Sq s 167suffix will be interpreted as the number of sectors (the default). 168All other suffixes are interpreted as per other numeric arguments, 169except that the number is converted into sectors by dividing by the 170sector size (as specified by 171.Fl S Ar secsize ) 172after suffix interpretation. 173.Pp 174If no 175.Fl s Ar size 176is specified then the filesystem size defaults to that of the partition, or, 177if 178.Fl F 179is specified, the existing file. 180.Pp 181If 182.Ar size 183is negative the specified size is subtracted from the default size 184(reserving space at the end of the partition). 185.It Fl V Ar verbose 186This controls the amount of information written to stdout: 187.Bl -tag -width 3n -offset indent -compact 188.It 0 189No output. 190.It 1 191Overall size and cylinder group details. 192.It 2 193A progress bar (dots ending at right hand margin). 194.It 3 195The first few super-block backup sector numbers are displayed before the 196progress bar. 197.It 4 198All the super-block backup sector numbers are displayed (no progress bar). 199.El 200The default is 3. 201If 202.Fl N 203is specified 204.Nm 205stops before outputting the progress bar. 206.It Fl v Ar volname 207This specifies a volume name for the file system. 208.It Fl Z 209Pre-zeros the file system image created with 210.Fl F . 211.El 212.Pp 213The following option overrides the standard sizes for the disk geometry. 214The default value is taken from the disk label. 215Changing this default is useful only when using 216.Nm 217to build a file system whose raw image will eventually be used on a 218different type of disk than the one on which it is initially created 219(for example on a write-once disk). 220Note that changing this value from its default will make it impossible for 221.Xr fsck_ext2fs 8 222to find the alternative superblocks if the standard superblock is lost. 223.Bl -tag -width Fl 224.It Fl S Ar sector-size 225The size of a sector in bytes (almost never anything but 512). 226Defaults to 512. 227.El 228.Sh NOTES 229There is no option to specify the metadata byte order on the file system 230to be created because the native ext2 file system is always little endian 231even on big endian hosts. 232.Pp 233The file system is created with 234.Sq random 235inode generation numbers to improve NFS security. 236.Pp 237The owner and group IDs of the root node and reserved blocks of the new 238file system are set to the effective UID and GID of the user initializing 239the file system. 240.Pp 241For the 242.Nm 243command to succeed, 244the disk label should first be updated such that the fstype field for the 245partition is set to 246.Ql Linux\ Ext2 , 247unless 248.Fl F 249or 250.Fl I 251is used. 252.Pp 253.\" To create and populate a filesystem image within a file use the 254.\" .Xr makefs 8 255.\" utility. 256.\" .Pp 257The partition size is found using 258.Xr fstat 2 , 259not by inspecting the disk label. 260The block size and fragment size will be written back to the disk label 261only if the last character of 262.Ar special 263references the same partition as the minor device number. 264.Sh SEE ALSO 265.Xr fstat 2 , 266.Xr disklabel 5 , 267.Xr disktab 5 , 268.Xr fs 5 , 269.Xr disklabel 8 , 270.Xr diskpart 8 , 271.\" .Xr dumpfs 8 , 272.\" .Xr format 8 , 273.Xr fsck_ext2fs 8 , 274.\" .Xr makefs 8 , 275.Xr mount 8 , 276.Xr mount_ext2fs 8 , 277.Xr newfs 8 278.Rs 279.%A Remy Card 280.%A Theodore Ts'o 281.%A Stephen Tweedie 282.%T "Design and Implementation of the Second Extended Filesystem" 283.%J "The Proceedings of the First Dutch International Symposium on Linux" 284.%U https://e2fsprogs.sourceforge.net/ext2intro.html 285.Re 286.Sh HISTORY 287The 288.Nm 289command first appeared in 290.Nx 5.0 . 291.Sh AUTHORS 292The 293.Nm 294command was written by 295.An Izumi Tsutsui 296.Aq tsutsui@NetBSD.org . 297.Sh BUGS 298The 299.Nm 300command is still experimental and there are few sanity checks. 301.Pp 302The 303.Nm 304command doesn't have options to specify each REV1 file system feature 305independently. 306.Pp 307The 308.Nm 309command doesn't support the bad block list accounted by the bad blocks inode. 310.Pp 311Many newer ext2 file system features (especially journaling) are 312not supported yet. 313.Pp 314Some features in file systems created by the 315.Nm 316command might not be recognized properly by the 317.Xr fsck_ext2fs 8 318utility. 319.Pp 320There is no native tool in the 321.Nx 322distribution for resizing ext2 file systems yet. 323