Linux Commands

How To Use MKFS for EXT4

Linux contains various types of filesystems, including EXT2, EXT3, and EXT4. You can manually build the file systems on the current device through the mkfs command. However, many beginners don’t know about this command and get errors while creating the file system.

So, if you also want to create a filesystem like EXT4 using the mkfs command, this tutorial is for you. This tutorial will provide brief information on the methods to use the MKFS for EXT4.

Table of contents

1. How To Use MKFS for EXT4
2. Example of mkfs.EXT4

How To Use MKFS for EXT4

Let’s start with the basic syntax you can use for the following mkfs command:

mkfs [-V] [-t fstype] [fs-options] filesys_name [blocks]

In the previous syntax, filesys_name indicates the device’s name or the file that should contain the filesystem. Execution of mkfs returns either 0 or 1. 0 indicates success, and 1 indicates failure.

In general, mkfs is also considered a front-end to build the various file systems on Linux. Here are the options you can try in the mkfs command:

  • -V: gives verbose output, useful in testing
  • -t fstype: specifies the type of the output file system
  • fs-options: following options are under this option
  • -c: checks the bad blocks in the device before building the filesystem
  • -l file_name: returns the list of bad blocks from the given file

The mke2fs command creates the ext2, ext3, or ext4 filesystems in a disk partition. A syntax for using the command is provided below:

mke2fs <options> </dev/device>

mke2fs -O journal_dev [ -b size_of_block] [ -L label_of_volume ] [ -n ] [ -q ] [ -v ] external_journal [ total_blocks ]

Let’s see the meaning of the parameters and options used with the mke2fs command:

  • device: unique file associated with the device
  • block_count: number of blocks on the device
  • -b block_size: This option returns the size of blocks in bytes. Some valid block sizes are 1024, 2048, and 4096 bytes per block
  • -c: This option checks the bad blocks in the device before creating the new filesystem
  • -E extended_options: Extended filesystem options can be set using this option. The following are some extended options:
  • stride=stride_size: Filesystems are configured for a RAID array using stride-size filesystem blocks. The block allocator uses this chunk size
  • stripe-width=stripe_width: Filesystems are configured for a RAID array using stride_width filesystem blocks per stripe. The block allocator can prevent the read-write modification of the parity in a RAID stripe
  • resize=max_online_resize: Sufficient space is reserved for the block group descriptor table to grow and support a filesystem with a max_online_resize block
  • test_fs: The flag is set in the filesystem superblock. It shows that the filesystem’s superblock can be mounted on experimental kernel code. For example, ext4dev filesystems
  • discard: At mkfs time, blocks are discarded, zeros the data, and mark not_yet_zeroed inode tables as zeroed. Speeds up the filesystem
  • nodiscard: No attempt of discard is made at mkfs time
  • -f fragment-size: The size of fragments in bytes is specified
  • -F: If the specified device is not a partition on a special block device, also mke2fs is forced to create a filesystem. If the specified file system is in use or mounted on a device, then also mke2fs is forced to create a filesystem
  • -g blocks-per-group: Mentions the number of blocks in the block group
  • -G number-of-groups: Mentions the number of block groups
  • -i bytes-per-inode: Mentions the ratio of the bytes/inode
  • -I inode-size: Mentions each inode’s size in bytes
  • -K: Will not attempt to discard the blocks at mkfs time
  • -l filename: Used to read the list of bad blocks from the given file
  • -m percentage_of_reserved_blocks: Mentions the percentage of the block of the filesystem to be reserved for the super user
  • -M last-mounted-directory: The last-mounted directory is set for the filesystem
  • -n: It does not create the filesystem using mke2fs. It only shows what it will do if it is created
  • resize_inode: Used to increase the size of the block group descriptor table in the future
  • -q: Used to quit the execution
  • -U UUID: The filesystem with the given UUID is created

Example of mkfs.EXT4

You can format the partition with the EXT4 filesystem through the mkfs.ext4 and /dev/device:

sudo mkfs.ext4 </dev/device>

Now, please check the partition for the bad block before performing the format process:

sudo mkfs.ext4 -c </dev/device>

You can now quietly create the EXT4 partitions on the </dev/device>

sudo mkfs.ext4 -q </dev/device>

Finally, create the EXT4 labeled rootfs on the existing partition and check the bad blocks with full verbose output:

sudo mkfs.etx4 -L rootfs -cv </dev/device>


In this tutorial, we have explained the methods briefly to use mkfs.EXT4. You can use this approach to create the filesystem on the device. Moreover, we discussed the mkfs command, mkfs for the ext4 filesystem, and options used with the mke2fs command.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.