mke2fs
Create ext2/ext3/ext4 filesystems
TLDR
Create an ext2 filesystem in partition 1 of device b (sdb1)
Create an ext3 filesystem in partition 1 of device b (sdb1)
Create an ext4 filesystem in partition 1 of device b (sdb1)
SYNOPSIS
mke2fs [ options ] device [ blocks-count ]
PARAMETERS
-t fstype
Specifies the filesystem type (ext2, ext3, or ext4). Defaults to ext4.
-b block-size
Specifies the block size in bytes. Valid values are powers of 2 between 1024 and 4096 (unless bigalloc is enabled).
-i bytes-per-inode
Specifies the bytes per inode ratio. Affects the number of inodes created.
-N number-of-inodes
Specifies the number of inodes to create.
-L volume-label
Sets the volume label for the filesystem.
-j
Creates an ext3 filesystem (journaled).
-J journal-options
Specifies ext3/4 journal options (e.g., size, device).
-O feature[,...]
Enables specific filesystem features.
-E extended-options
Specifies extended options (e.g., stride, stripe-width).
-F
Force creation even if device is mounted.
-v
Verbose mode.
device
The device (partition) to format.
blocks-count
The number of blocks to create on the device. if omitted, the command use the full size of the device
DESCRIPTION
mke2fs is used to create ext2, ext3, or ext4 filesystems on devices, usually disk partitions. It's a fundamental tool for preparing storage for use with Linux. It formats the device, setting up the necessary metadata structures, including the superblock, inode tables, and journal (for ext3/4).
The command allows for extensive customization of the filesystem, including block size, inode ratio, reserved blocks, and journal size. Choosing appropriate values is critical for optimal performance and storage utilization based on the intended workload and the size of the storage device. Improper use can lead to wasted space or performance bottlenecks. mke2fs detects the device size and sets reasonable defaults, but manual configuration is often necessary for specific use cases.
CAVEATS
Using mke2fs on a device containing data will erase all data. Incorrect parameters can lead to performance problems or wasted space.
FILESYSTEM TYPES
ext2: A basic filesystem without journaling. Faster than ext3/4 on older hardware but more prone to data loss in case of a crash.
ext3: Adds journaling to ext2, providing better data integrity.
ext4: The successor to ext3, offering improved performance, larger filesystem sizes, and advanced features like extent-based allocation.
INODE RATIO
The inode ratio (-i) determines how many inodes are created. A smaller ratio (more inodes) is better for storing many small files, while a larger ratio (fewer inodes) is better for storing fewer large files. The default value is usually appropriate for general-purpose use.
WHEN TO USE <B>-F</B>
The -F option should be used with caution, as it can potentially corrupt data if used incorrectly. It's primarily intended for situations where the filesystem is somehow marked as mounted but is not actually in use, or when there is a lock issue that prevents formatting the device.
HISTORY
mke2fs evolved alongside the ext2 filesystem, which was created as a replacement for the MINIX filesystem. It was later adapted to support ext3 (with journaling) and ext4 (with advanced features).
The command has been continuously developed and refined to support new features and improve performance. It's a core component of most Linux distributions.