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 xargs Command: Pass Standard Input as Command Arguments

Linux xargs Command: Pass Standard Input as Command Arguments

Learn how to pass Standard Input as Command Arguments with the Linux xargs 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 dnf Command: Manage RPM Distribution Packages

Linux dnf Command: Manage RPM Distribution Packages

Learn how to manage RPM Distribution Packages with the Linux dnf command, including practical examples, key options, and important precautions.

Linux renice Command: Change the Priority of a Running Process

Linux renice Command: Change the Priority of a Running Process

Learn how to change the Priority of a Running Process with the Linux renice command, including practical examples, key options, and important precautions.

Linux watch Command: Run a Command Repeatedly

Linux watch Command: Run a Command Repeatedly

Learn how to use the Linux watch command to rerun a command at regular intervals and highlight changing output, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux paste Command: Join Corresponding Lines Side by Side

Linux paste Command: Join Corresponding Lines Side by Side

Learn how to join Corresponding Lines Side by Side with the Linux paste command, including practical examples, key options, and important precautions.

Linux which Command: Find Executables in PATH

Linux which Command: Find Executables in PATH

Learn how Linux which searches PATH for executables, shows all matching paths, differs from type and command -v, and should be used carefully in scripts.

Linux Tutorial / Search and Process Text with grep, sort, uniq, cut, and wc

Linux Tutorial / Search and Process Text with grep, sort, uniq, cut, and wc

Practice searching, sorting, grouping, extracting, and counting text with grep, sort, uniq, cut, and wc, including reproducible output and key caveats.

Linux rsync Command: Synchronize Files and Directories

Linux rsync Command: Synchronize Files and Directories

Learn how to synchronize Files and Directories with the Linux rsync command, including practical examples, key options, and important precautions.

Linux Tutorial / File Permissions and Safe sudo Use

Linux Tutorial / File Permissions and Safe sudo Use

Learn to read file and directory permissions, practice chmod safely, and understand when to use sudo and how to diagnose access errors.