In Unix and Unix-like operating systems, <code>mkfs</code> is a command used to format a block storage device with a specific file system. In those systems, a block storage device must be formatted with a file system before it can be mounted and accessed through the operating system's filesystem hierarchy.
In 4.2BSD, <code>newfs</code> was a front end for <code>mkfs</code>; in 4.3-Tahoe, <code>newfs</code> replaced <code>mkfs</code>.
The command was originally implemented in the first version of Unix as a method to initialize either a DECtape (using the "t" argument) or an RK03 disk pack (using the "r" argument). The initialization process would write formatting data to the device so that it contained an empty file system. It created the super-block, i-list, and free list on the storage device and established the root directory with entries for "." and ".." (self and parent, respectively). The RK03 disk packs had 4872 available blocks after initialization, while the tapes had 578 blocks (at 512 bytes/block). The mkfs executable was kept in the /etc directory instead of a binary directory so it would not be inadvertently called and destroy information.
In Version 6 Unix, <code>mkfs</code> took, as its second argument, the name of a file containing parameters to be used when creating the file system; if the file cannot be opened, it's treated as the number of blocks in the partition in which the file system is being created. The <code>mkfs</code> in Version 7 Unix was the same. Unix System III added some optional arguments.
4.2BSD added newfs as a front end for <code>mkfs</code>; in 4.3-Tahoe,<code>newfs</code> replaced <code>mkfs</code>.
Many Unix-like operating systems include the mkfs command, the newfs command, or both. This includes HP-UX, Minix, SunOS, Solaris and Linux.
The basic syntax of the command, which is common to all modern implementations, is:
where '<code>fs type</code>' is the type of the filesystem and '<code>device</code>' is the target UNIX device to write the filesystem data to. Usually the "device" is a drive partition. Often the command is simply a wrapper for another command that performs the formatting for a specific file system. For example,
would call the command <code>mke2fs</code> while passing along the appropriate arguments to format the device <code>/dev/sda1</code> with the ext3 filesystem. The default options for the command are stored in the file <code>mke2fs.conf</code>, usually in the <code>/etc</code> directory. Depending on the implementation and the specific file system requested, the command may have many options that can be specified such as inode size, block size, volume label, and other features. (See file system for details)
The filesystem-specific commands that mkfs calls may be invoked directly by the user from the command line. In Linux, the convention has been to name the filesystem-specific commands as: <code>mkfs.<fs-type></code>. Where <code><fs-type></code> is an abbreviation for the file system, e.g., <code>mkfs.ext2</code>, <code>mkfs.msdos</code>, <code>mkfs.minix</code>, etc. File systems supported by the command vary by implementation and include: MSDOS, SCO bfs, CPM, ext2, ext3, ext4, minix, fat (vfat), HFS, VXFS, RF disk, RK disk, DECtape, and NTFS.