mkfs.ext4
Create an ext4 filesystem
TLDR
Create an ext4 filesystem inside partition Y on device X
Create an ext4 filesystem with a volume-label
SYNOPSIS
mkfs.ext4 [options] device [blocks-count]
PARAMETERS
-b block-size
Specify the size of blocks in bytes (e.g., 1024, 2048, 4096). Default is 4096 bytes.
-c
Check the device for bad blocks before creating the filesystem, using a read-only test.
-L volume-label
Set the filesystem volume label (e.g., MY_DATA). This label can be used to mount the filesystem.
-N number-of-inodes
Override the default number of inodes to create. Inodes store metadata about files and directories.
-O feature[,...]
Enable or disable specific ext4 filesystem features. Multiple features can be separated by commas.
-E extended-option[,...]
Set extended filesystem options, such as 'stride' (RAID chunk size) or 'stripe-width' (RAID stripe size).
-F
Force the creation of the filesystem, even if a valid filesystem or an existing partition table is detected on the device.
-q
Execute quietly, suppressing most output messages during filesystem creation.
-v
Produce verbose output, showing more details about the filesystem creation process.
-U UUID
Set the Universally Unique Identifier (UUID) for the filesystem. A new UUID is generated by default.
device
The special file representing the device (e.g., /dev/sdb1, /dev/mapper/my_volume) where the filesystem will be created.
blocks-count
The number of blocks on the device to be used for the filesystem. If omitted, the entire device or partition will be used.
DESCRIPTION
The mkfs.ext4 command is used to build an ext4 filesystem on a designated storage device, such as a disk partition or a logical volume. It initializes the necessary on-disk structures, including the superblock, inode tables, and data blocks, which are fundamental for the filesystem's operation.
As the default and highly recommended filesystem for many Linux distributions, ext4 provides significant advancements over its predecessors, ext2 and ext3. These enhancements include support for larger file and volume sizes, improved performance, and enhanced data integrity through robust journaling. This command is essential for preparing new or existing storage devices for use, enabling the operating system to store and retrieve data efficiently and reliably.
When executed, mkfs.ext4 will erase all existing data on the target device, making it a powerful yet potentially destructive utility. Users must exercise extreme caution and verify the correct device path before proceeding with execution.
CAVEATS
Using mkfs.ext4 is a destructive operation; it will erase all existing data on the specified device. Always double-check the device path before executing the command to prevent accidental data loss. This command typically requires root privileges to execute successfully. Creating a filesystem on a device that is currently mounted can lead to severe data corruption and system instability.
DEFAULT BEHAVIOR
By default, mkfs.ext4 creates a journaled filesystem, which is a core feature of ext4 ensuring data integrity in case of unexpected shutdowns. It intelligently optimizes the filesystem layout based on the device size and provides sensible defaults for inode density and block size if not explicitly specified. It also automatically enables crucial ext4 features like dir_index, filetype, has_journal, and extent, which are fundamental to ext4's performance, scalability, and capabilities.
USAGE EXAMPLE
To create an ext4 filesystem on partition /dev/sdb1 with a label 'MY_DATA':sudo mkfs.ext4 -L MY_DATA /dev/sdb1
To force creation on /dev/sdc2 and check for bad blocks:sudo mkfs.ext4 -F -c /dev/sdc2
HISTORY
mkfs.ext4 is part of the e2fsprogs suite of utilities, which are designed for managing ext2, ext3, and ext4 filesystems. It acts as a specialized front-end wrapper to the more generic mke2fs command, automatically configuring the necessary options to create an ext4 filesystem.
The ext4 filesystem itself was introduced as a significant evolution from ext3, making its debut in the Linux kernel 2.6.19 in 2006 and achieving stable status in version 2.6.28 in 2008. mkfs.ext4 was developed in conjunction with ext4 to specifically handle its new features, such as extents (for improved large file handling), larger timestamps, and persistent pre-allocation.