Skip to content

mkfs Linux Command Guide

The Linux mkfs command is used to create a new filesystem on a storage device. It allows users to format a block-based device with the specified filesystem type, such as ext4 or xfs. The mkfs command offers various options and allows customization of the filesystem parameters, such as block size, journaling, and metadata options. By understanding the syntax and available options of the mkfs command, users can efficiently manage and format storage devices according to their requirements.

mkfs Syntax:

Terminal window
mkfs [options] [parameters]

Options:

OptionDescription
-t Specify the type of file system to create (e.g., ext4, xfs).
-cPerform bad blocks scan during formatting.
-l Assign a label to the file system.
-nDo not create the file system, show what would be done.
-FForce operation even if not safe.
-VVerbose mode - show progress.
-qQuiet mode - suppress output.
Indicates the end of options.

Parameters:

ParameterDescription
deviceThe block device to format.
inode_countThe number of inodes to allocate.
block_countThe number of blocks to allocate.
block_sizeThe size of a block in bytes.
inode_sizeThe size of an inode in bytes.
labelThe label for the file system.
reserved_blocksThe amount of space reserved for super-user.
block_group_sizeThe size of cylinder groups in blocks.
strideThe number of filesystem blocks that should be read or written together.
stripe_widthThe number of blocks in a stripe of the RAID.
stripe_widthThe number of blocks in a stripe of the RAID.

mkfs Command Samples:

Create an ext4 File System on /dev/sda1

Terminal window
mkfs.ext4 /dev/sda1

Formats the partition /dev/sda1 with the ext4 file system.

Create a FAT32 File System on /dev/sdb1

Terminal window
mkfs.vfat /dev/sdb1

Formats the partition /dev/sdb1 with the FAT32 file system.

Create an XFS File System on /dev/sdc1

Terminal window
mkfs.xfs /dev/sdc1

Formats the partition /dev/sdc1 with the XFS file system.

Create a Btrfs File System on /dev/sdd1

Terminal window
mkfs.btrfs /dev/sdd1

Formats the partition /dev/sdd1 with the Btrfs file system.

Create an ext2 File System on /dev/sde1

Terminal window
mkfs.ext2 /dev/sde1

Formats the partition /dev/sde1 with the ext2 file system.

Create a ReiserFS File System on /dev/sdf1

Terminal window
mkfs.reiserfs /dev/sdf1

Formats the partition /dev/sdf1 with the ReiserFS file system.

Create an NTFS File System on /dev/sdg1

Terminal window
mkfs.ntfs /dev/sdg1

Formats the partition /dev/sdg1 with the NTFS file system.

mkfs FAQ:

How do I use mkfs in Linux?

To use the mkfs command in Linux, execute the following command:

Terminal window
mkfs --type ext4 /dev/sdX

What is the purpose of mkfs in Linux?

The mkfs command in Linux is used to create a filesystem on a specific partition or device.

How can I specify the filesystem type with mkfs?

You can specify the filesystem type using the “—type” option followed by the desired filesystem type. For example:

Terminal window
mkfs --type xfs /dev/sdX

Can I force the creation of a filesystem with mkfs?

Yes, you can force the creation of a filesystem using the “—force” option.

Terminal window
mkfs --type ext4 --force /dev/sdX

How do I display the progress of mkfs operation?

You can display the progress of the mkfs operation by using the “—verbose” option.

Terminal window
mkfs --type ext4 --verbose /dev/sdX

Is it possible to label a filesystem created with mkfs?

Yes, you can label a filesystem by using the “—label” option followed by the desired label name.

Terminal window
mkfs --type ext4 --label mydrive /dev/sdX

Applications of the mkfs command

  1. Creating a new file system on a disk partition.
  2. Formatting a disk or partition with a specific file system.
  3. Initializing a disk or partition for use with a specific file system.
  4. Creating a file system on a disk or partition for data storage.