Linux mkfs Command: Create a New Filesystem

mkfs creates a new file system on a device or partition. If there is an existing file system and data on the target, it can be overwritten, so identifying the device and backing up data before execution is essential.

What is the mkfs command?

mkfs is a front-end that calls file system-specific creation tools. In actual management, tools that specify the format, such as mkfs.ext4 or mkfs.xfs, are often used. Creating a partition and creating a file system within it are different tasks.

Basic syntax

sudo mkfs -t filesystem_type device

Installed implementations and options may vary depending on the distribution. Check the description on your current system with man mkfs.

Examples

Checking target devices and data

Before formatting, check the partition's type, UUID, size, and mount status.

lsblk -f

File system creation syntax

The following is the syntax of a destructive command; replace the example with the actual device path only after backing up your data and verifying the target device.

sudo mkfs.ext4 /dev/device_name

Query result identification information

After the operation, check the format and the new UUID.

sudo blkid /dev/device_name

Values to check after formatting

Commands like mkfs.ext4 that create a filesystem can erase existing data on the target partition. Before running one on a real device, use lsblk -f and findmnt to verify the target and mount status, and prepare a backup.

lsblk -f
sudo mkfs.ext4 /dev/sdb1
sudo blkid /dev/sdb1

Example of expected output format from the final check after formatting completes successfully:

/dev/sdb1: UUID="..." TYPE="ext4"

Since the UUID is newly generated when actually executed, you should not copy the dots from the example for use in your settings. Even if the formatting tool outputs a success message, it does not mean the data can be recovered. If your goal is simply to mount an existing filesystem, mkfs is not necessary.

Creating a partition and creating a filesystem are different operations. Making a partition with fdisk or parted does not automatically create ext4 or XFS inside it. If you only intend to mount an existing filesystem, formatting it instead would destroy data.

Main Options and Format

Options/Format Description
-t format Specify the file system format to create in the mkfs frontend.
mkfs.ext4 A creation tool exclusively for ext4 file systems.
mkfs.xfs A creation tool exclusively for XFS file systems.
-L label Assign a label if supported by the file system-specific tool.

Precautions when using

Formatting can overwrite existing data and change the UUID, and there is no simple undo command. Make sure the target is not mounted and confirm if it is an OS or backup disk, and verify backups on separate media. File system-specific options and size limits vary, so check the manual of the actual creation tool, such as man mkfs.ext4.

Frequently Asked Questions

Does running mkfs also create a partition?

No. mkfs creates a file system on the selected device. Creating a partition table and partitions are separate operations, performed with tools like fdisk or parted.

Official Documentation

You can check the exact behavior of the options and implementation differences in the official documentation for mkfs.

More in This Category
Linux locate Command: Search Indexed File Paths Quickly

Linux locate Command: Search Indexed File Paths Quickly

Learn how Linux locate searches a filename database, how updatedb affects freshness, how to limit and filter matches, and when find is the better tool.

Linux ip Command: Inspect and Configure Network Interfaces and Routes

Linux ip Command: Inspect and Configure Network Interfaces and Routes

Learn how to inspect and Configure Network Interfaces and Routes with the Linux ip command, including practical examples, key options, and important precautions.

Bash Command Operators Explained: ;, &&, ||, &, and |

Bash Command Operators Explained: ;, &&, ||, &, and |

Understand how Bash operators run commands sequentially, conditionally, in the background, or through pipelines, with practical examples and precedence guidance.

Linux gunzip Command: Decompress gzip Files

Linux gunzip Command: Decompress gzip Files

Learn how to decompress gzip Files with the Linux gunzip command, including practical examples, key options, and important precautions.

Linux find Command: Search Files by Name, Type, Size, and Time

Linux find Command: Search Files by Name, Type, Size, and Time

Learn how to search with Linux find by name, file type, size, and modification time, combine expressions, run commands safely, and verify targets before deletion.

Linux ls Command: List Files and Directories

Linux ls Command: List Files and Directories

Learn how to use the Linux ls command to list files and directories with permissions, sizes, timestamps, and sorting options, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux host Command: Look Up DNS Names and Addresses

Linux host Command: Look Up DNS Names and Addresses

Learn how to look Up DNS Names and Addresses with the Linux host command, including practical examples, key options, and important precautions.

How to Check the Linux Distribution, Version, Kernel, and Architecture

How to Check the Linux Distribution, Version, Kernel, and Architecture

Learn how to identify a Linux distribution and version with /etc/os-release, then check the running kernel and CPU architecture with hostnamectl and uname. The guide also covers scripts, legacy systems, containers, WSL, and chroot environments.

Linux free Command: Check Memory and Swap Usage

Linux free Command: Check Memory and Swap Usage

Learn how to use the Linux free command to inspect available memory, used memory, cache, and swap usage, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux ethtool Command: Inspect Network Link and Driver Settings

Linux ethtool Command: Inspect Network Link and Driver Settings

Learn how to inspect Network Link and Driver Settings with the Linux ethtool command, including practical examples, key options, and important precautions.