Linux Command: mkfs
Build a filesystem on a device partition
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]... DEVICEKey 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/sdb1Create with label
sudo mkfs.ext4 -L "BackupDisk" /dev/sdb1Create XFS
sudo mkfs.xfs /dev/sdb1Pro 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 โ