mkfs
Create a filesystem on a device
TLDR
Build a Linux ext2 filesystem on a partition
Build a filesystem of a specified type
Build a filesystem of a specified type and check for bad blocks
SYNOPSIS
mkfs [-t fstype] [options] device
PARAMETERS
-t fstype
Specifies the type of filesystem to create (e.g., ext4, xfs, vfat).
Required unless the filesystem type can be inferred from the device.
-V
Verbose mode; provides more detailed output during filesystem creation.
-c
Check the device for bad blocks before creating the filesystem.
-l filename
Read bad blocks list from filename.
-v
Be verbose
-q
Run quietly
-m percentage
Percentage of blocks reserved for super-user.
device
The device (e.g., /dev/sda1) on which to create the filesystem. WARNING: This will overwrite any existing data on the device.
DESCRIPTION
The mkfs command in Linux is a utility for creating a filesystem on a device, typically a disk partition. It acts as a front-end to various filesystem-specific tools like mkfs.ext4, mkfs.xfs, and mkfs.vfat, selecting the appropriate tool based on the filesystem type specified by the user.
The command writes the necessary metadata structures to the device, effectively initializing it for use as a filesystem. This includes creating the superblock, inodes, and other data structures required for the filesystem to operate.
Using mkfs carefully is essential, as it will overwrite any existing data on the target device. Therefore, it's crucial to specify the correct device and filesystem type to avoid data loss. The command provides options for specifying various filesystem parameters, such as block size, inode ratio, and journal size, though defaults are usually sufficient for most use cases. It is commonly used during system installation or when formatting a new storage device.
CAVEATS
Using mkfs will destroy all data on the specified device.
Double-check the device name and filesystem type before running the command.
Running mkfs requires root privileges.
FILESYSTEM-SPECIFIC OPTIONS
Each filesystem type (e.g., ext4, xfs) has its own set of specific options that can be passed to mkfs. These options are passed through to the underlying filesystem-specific tool (e.g., mkfs.ext4). Refer to the manual pages for these tools for details on the available options.
EXIT STATUS
mkfs returns 0 on success and a non-zero value on failure. Failures can occur due to invalid arguments, insufficient permissions, or errors during filesystem creation.
HISTORY
The mkfs command has been a standard part of Unix-like operating systems for many years. It provides a generic interface to create various filesystem types. Over time, the specific tools that mkfs calls (e.g., mkfs.ext4) have evolved to support new features and improvements in filesystem technology. The core functionality of providing a unified command-line interface for creating filesystems has remained consistent.