mkfs.ext4 Command Examples in Linux

Ext4 is a native Linux filesystem, developed as the successor to ext3, and it was (and for some distributions still is) the default filesystem for many years. It offers stability, high capacity, reliability, and performance while requiring minimal maintenance. On top of that, you can resize (increase/decrease) the filesystem without a problem.

The mkfs.ext4 command can create an ext4 file system from disk partitions. This command is a symbolic link of the mke2fs command, and its usage is the same as the mke2fs command.

Syntax:

# mkfs [-t fstype] [fs_options] device

To create an ext4 filesystem, use:

# mkfs.ext4 -L [label] [partition]

The label is optional but makes it easier to recognize a filesystem.

Most Commonly used Command Options

Options Description
-c Check the partition for bad blocks before formatting
-q No information is displayed during execution
-b block-size Specify the block size, the default configuration file is in /etc/mke2fs.conf, blocksize = 4096
-F Forced formatting

mkfs.etx4 Command Examples

1. Format the disk /dev/sdd as a ext4 partition:

# mkfs.ext4 /dev/sdd

2. Check the partition for bad blocks before formatting:

# mkfs.ext4 -c /dev/sdb

3. Using defaults, quietly create an ext4 partition on /dev/hda3:

# mkfs.ext4 -q /dev/hda3

4. Create an ext4 filesystem labeled rootfs on existing partition /dev/hda3, checking for bad blocks and with full verbose output:

# mkfs.etx4 -L rootfs -cv /dev/hda3

Final Thoughts

Ext4 is not the fastest filesystem around, but for many workloads the gap between ext4 and the competition is very small.

The most important utilities are:

  • mkfs.ext4: Format the filesystem
  • e2label: Change the label of the filesystem
  • tune2fs: Change the parameters of the filesystem
  • dump2fs: Show the parameters of the filesystem
  • resize2fs: Change the size of the filesystem
  • fsck.ext4: Check and repair the filesystem
  • e2freefrag: Report on defragmentation
  • e4defrag: Defrag filesystem, normally not needed
Related Post