mke2fs – Create an “ETC2/ETC3” Filesystem on a Disk Partition

The mke2fs command is used to create a new “ext2/ext3” filesystem on a disk partition. This command is used to format a disk partition with the “ext2” or “ext3” filesystem. The “ext2” filesystem is an older version of the “ext3” filesystem, which is a journaled filesystem.

Overview

The syntax for the mke2fs command is as follows:

mke2fs [options] device

Here, device refers to the block device or partition on which the filesystem is to be created. The mke2fs command creates an “ext2” or “ext3” filesystem on the specified device. The options available for this command are listed below.

Examples

To create an “ext3” filesystem on the partition /dev/sda1, use the following command:

mke2fs -t ext3 /dev/sda1

To create an “ext2” filesystem on the partition /dev/sdb2, use the following command:

mke2fs -t ext2 /dev/sdb2

Use Cases

The mke2fs command is typically used when setting up a new disk partition or when reformatting an existing partition. This command can be used to create a new filesystem on a partition that has never been formatted before, or to reformat a partition that previously had a different filesystem.

Options

The following options are available for the mke2fs command:

Option Description
-b block-size Set the block size of the filesystem.
-c Check the device for bad blocks before creating the filesystem.
-F Force the creation of the filesystem, even if the device already contains a filesystem.
-i bytes-per-inode Set the bytes per inode of the filesystem.
-j Create an “ext3” filesystem.
-J journal-options Set journal options for the filesystem.
-L volume-label Set the volume label of the filesystem.
-m reserved-blocks-percentage Set the percentage of blocks reserved for the super-user.
-N Do not create a filesystem, just print out the parameters that would be used.
-O feature[,...] Set filesystem features.
-q Quiet mode.
-r Create a “ext2” filesystem.
-T usage-type Set the usage type of the filesystem.
-U uuid Set the UUID of the filesystem.
-v Verbose mode.
-V Print the version of the mke2fs command.

Troubleshooting Tips

  • If the mke2fs command fails with an error message, make sure that the device is not mounted. The mke2fs command cannot create a filesystem on a mounted device.
  • If the device already contains a filesystem, use the -F option to force the creation of a new filesystem. Note that this will erase all data on the device.
  • If the device has bad blocks, use the -c option to check for bad blocks before creating the filesystem. Note that this may take a long time, depending on the size of the device.

Notes

  • The mke2fs command is typically used with the mkfs command, which is a wrapper command that automatically selects the appropriate filesystem creation tool based on the specified filesystem type. For example, the command mkfs.ext3 /dev/sda1 is equivalent to mke2fs -t ext3 /dev/sda1.
  • The “ext2” and “ext3” filesystems are commonly used on Linux systems, but they are not the only filesystems available. Other popular filesystems include “ext4”, “XFS”, and “Btrfs”.