๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

๐Ÿ’ก Disk & Storage October 7, 2026 5

Linux Command: mkfs

Build a filesystem on a device partition

Terminal โ€” Disk & Storage
Command
$ sudo mkfs.ext4 /dev/sdb1

mkfs (make filesystem) creates a filesystem on a disk partition or device. It formats the raw storage so it can store files and directories. mkfs is actually a frontend โ€” the real work is done by type-specific tools like mkfs.ext4, mkfs.xfs, etc. mkfs is used after partitioning with fdisk to prepare a partition for use. The most common filesystem types are ext4 (Linux default), xfs (RHEL default), and vfat (for USB drives and EFI partitions). WARNING: mkfs destroys all existing data on the target partition. Always double-check the device before formatting.

Syntax

mkfs [OPTION]... DEVICE

Key Options

  • -t โ€” Specify filesystem type
  • .ext4 โ€” Create ext4 filesystem (most common)
  • .xfs โ€” Create XFS filesystem
  • .vfat โ€” Create FAT32 filesystem
  • -L โ€” Set volume label
  • -n โ€” Dry run (some implementations)

Examples

Create ext4 filesystem

sudo mkfs.ext4 /dev/sdb1

Create with label

sudo mkfs.ext4 -L "BackupDisk" /dev/sdb1

Create XFS

sudo mkfs.xfs /dev/sdb1

Pro Tips

  • mkfs completely erases the partition. Triple-check the device name with lsblk before running. There is no undo.
  • ext4 is the best default choice โ€” mature, well-supported, good performance, and journaling for reliability.
  • After formatting, mount the filesystem: sudo mount /dev/sdb1 /mnt/data. Add to /etc/fstab for permanent mount.

Learn more: Full mkfs reference โ†’

Share this tip