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.









