mkfs Command
Advanced Disk & Storage man(1)Build a filesystem on a device partition
👁 9 views
📅 Updated: Mar 15, 2026
SYNTAX
mkfs [OPTION]... DEVICE
What Does mkfs Do?
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.
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.
Options & Flags
| Option | Description | Example |
|---|---|---|
| -t | Specify filesystem type | mkfs -t ext4 /dev/sdb1 |
| .ext4 | Create ext4 filesystem (most common) | mkfs.ext4 /dev/sdb1 |
| .xfs | Create XFS filesystem | mkfs.xfs /dev/sdb1 |
| .vfat | Create FAT32 filesystem | mkfs.vfat /dev/sdb1 |
| -L | Set volume label | mkfs.ext4 -L "Data" /dev/sdb1 |
| -n | Dry run (some implementations) | mkfs.ext4 -n /dev/sdb1 |
Practical Examples
#1 Create ext4 filesystem
Formats partition as ext4 — the most common Linux filesystem.
$ sudo mkfs.ext4 /dev/sdb1#2 Create with label
Creates ext4 filesystem with a volume label.
$ sudo mkfs.ext4 -L "BackupDisk" /dev/sdb1#3 Create XFS
Creates an XFS filesystem — good for large files and high performance.
$ sudo mkfs.xfs /dev/sdb1#4 Create FAT32 for USB
Creates FAT32 — compatible with Windows, macOS, and Linux.
$ sudo mkfs.vfat -F 32 /dev/sdc1#5 Full workflow
Complete disk setup: partition, format, mount.
$ sudo fdisk /dev/sdb # Create partition\nsudo mkfs.ext4 /dev/sdb1\nsudo mount /dev/sdb1 /mnt/dataTips & Best Practices
DESTROYS ALL DATA: mkfs completely erases the partition. Triple-check the device name with lsblk before running. There is no undo.
ext4 for most Linux use: ext4 is the best default choice — mature, well-supported, good performance, and journaling for reliability.
After mkfs: After formatting, mount the filesystem: sudo mount /dev/sdb1 /mnt/data. Add to /etc/fstab for permanent mount.
Frequently Asked Questions
How do I format a partition?
sudo mkfs.ext4 /dev/sdX1 (replace X1 with correct device). Check with lsblk first.
Which filesystem should I use?
ext4 for general Linux use. xfs for large files. vfat/fat32 for USB drives shared with Windows. btrfs for advanced features.
How do I format a USB drive?
sudo mkfs.vfat -F 32 /dev/sdX1 for maximum compatibility. Or mkfs.ext4 for Linux-only use.
Related Commands
More Disk & Storage Commands
Master Linux with Professional eBooks
Curated IT eBooks covering Linux, DevOps, Cloud, and more
Browse Books →