Quick take: The mkfs command creates a filesystem on a partition — effectively formatting it. sudo mkfs.ext4 /dev/sdX1 makes an ext4 filesystem. This erases everything on the partition, so confirm the device with lsblk first.

Introduction

After partitioning a disk, you must put a filesystem on it before it can store files — that is what mkfs (make filesystem) does. You choose the type, such as ext4 for general Linux use, xfs for large-scale storage, or vfat for cross-platform USB drives. Because it erases the target, mkfs must be used with care.

This guide covers creating common filesystem types, adding labels, and the place mkfs holds in the partition-to-mount workflow.

Syntax

The basic syntax of the mkfs command is:

mkfs.TYPE [OPTIONS] DEVICE

Common Options and Parameters

The most useful options and parameters for the mkfs command:

OptionDescription
mkfs.ext4Create an ext4 filesystem (general Linux use).
mkfs.xfsCreate an XFS filesystem (large files/volumes).
mkfs.vfatCreate a FAT filesystem (cross-platform USB).
-L LABELSet a filesystem label.
-n LABELSet the label for vfat.
mkfs -t TYPEGeneric form specifying the type.
-fForce creation (xfs, overwrite existing).

Practical Examples

Real mkfs commands you can run today:

# Confirm the target device first
lsblk
# Create an ext4 filesystem
sudo mkfs.ext4 /dev/sdb1
# Create ext4 with a label
sudo mkfs.ext4 -L data /dev/sdb1
# Create an XFS filesystem
sudo mkfs.xfs /dev/sdb1
# Format a USB drive as FAT32
sudo mkfs.vfat -n USB /dev/sdc1
# Then mount it
sudo mount /dev/sdb1 /mnt/data

Tips and Best Practices

  • mkfs erases the partition. Triple-check the device name with lsblk — formatting the wrong one destroys its data.
  • Choose the type to suit the job: ext4 for general use, xfs for very large files and volumes, vfat for USB drives shared with Windows and macOS.
  • Add a label with -L so you can reference the filesystem by name in /etc/fstab and lsblk -f.

Final Thoughts

mkfs turns a raw partition into a usable filesystem, the step between fdisk and mount. Pick the right type — ext4, xfs, or vfat — label it for convenience, and above all verify the device with lsblk because formatting is destructive. Once created, mount it and, if it should persist, add it to /etc/fstab.

FAQ: mkfs Command in Linux

How do I format a partition in Linux?+

Use mkfs with the filesystem type: sudo mkfs.ext4 /dev/sdX1 creates an ext4 filesystem. This erases the partition, so confirm the device with lsblk first, then mount it to use it.

Which filesystem type should I use?+

ext4 is the safe default for general Linux storage. xfs suits very large files and volumes, and vfat (FAT32) is best for USB drives shared with Windows and macOS.

How do I add a label to a filesystem?+

Use -L with mkfs: sudo mkfs.ext4 -L data /dev/sdX1 labels it 'data'. You can then reference it by label in /etc/fstab and see it in lsblk -f.

Does mkfs erase data?+

Yes. Creating a filesystem overwrites the partition's contents, destroying any existing data. Always verify the target device with lsblk and back up anything important before running mkfs.

What are the steps to add a new disk?+

Partition it with fdisk or parted, create a filesystem with mkfs, create a mount point with mkdir, mount it with mount, and add it to /etc/fstab (by UUID) to mount automatically at boot.

Need help with Linux servers or infrastructure?

Work directly with Muhammad Irfan Aslam for Linux, Ubuntu, Docker, DevOps, cloud, CI/CD, or infrastructure support.

Hire Me for Support