mkfs (make filesystem) is the Linux command that creates a new, empty filesystem on a block device such as a disk partition, a logical volume or an image file. In Linux filesystem administration, it is the step between partitioning a disk and mounting it: mkfs writes the superblock, allocation structures, inode tables and root directory that turn raw sectors into storage the kernel can mount.
Running mkfs is destructive by design. It overwrites the metadata of any existing filesystem on the target, so the previous files become inaccessible for practical purposes. Choosing the correct device and filesystem type is therefore the most important part of using the command.
How mkfs builds a filesystem
The mkfs command itself is a thin front end from the util-linux package. Given -t type, it calls a filesystem-specific builder named mkfs.type, such as mkfs.ext4, mkfs.xfs or mkfs.btrfs, and passes the remaining options through. Modern documentation recommends calling the specific builder directly, and the generic wrapper is considered deprecated in favor of those tools.
The builder computes the filesystem geometry from the device size and options, then writes the on-disk structures. For ext4 this means block groups, each with a block bitmap, an inode bitmap and an inode table, plus a primary superblock and backup superblock copies. XFS instead creates allocation groups with B+tree indexes, while Btrfs writes a superblock and initial copy-on-write trees.
Most builders also assign a filesystem UUID and an optional label, which blkid and lsblk later report and which fstab can reference. On SSDs and thin-provisioned storage, many builders first issue a discard (TRIM) of the whole device, which can take noticeable time on large drives.
The table below lists the most common builders and what they create.
| Builder | Filesystem | Typical use |
|---|---|---|
| mkfs.ext4 | ext4 | General-purpose Linux root and data volumes |
| mkfs.xfs | XFS | Large volumes and parallel workloads |
| mkfs.btrfs | Btrfs | Snapshots, checksums and subvolumes |
| mkfs.vfat | FAT32 | EFI system partitions and removable media |
| mkfs.f2fs | F2FS | Flash storage such as SD cards |
| mkswap | Swap area | Swap partitions, not a filesystem |
Key mkfs options and parameters
Most mkfs parameters are fixed at creation time and cannot be changed later without reformatting, which is why they deserve attention before the command runs. Options differ between builders, but the same concepts recur: block size, inode allocation, labels, reserved space and journal settings.
| Parameter | Example option | What it affects |
|---|---|---|
| Block size | mkfs.ext4 -b 4096 | Allocation unit, usually 4 KiB matching page size |
| Inode ratio | mkfs.ext4 -i 16384 | Maximum number of files on ext4 |
| Reserved blocks | mkfs.ext4 -m 1 | Space kept for root, 5 percent by default |
| Label | -L data or -n DATA for vfat | Human-readable name for mounting |
| Stripe alignment | mkfs.xfs -d su=64k,sw=4 | Performance on RAID arrays |
| Data profile | mkfs.btrfs -d raid1 -m raid1 | Redundancy across multiple devices |
| Force overwrite | -f (XFS, Btrfs) or -F (ext4) | Proceeds despite an existing signature |
The inode count matters most on ext4, because ext4 allocates inodes statically. A volume holding millions of small files, such as a mail spool or a cache directory, can report no space left on device while gigabytes remain free if the inode ratio was too high. XFS and Btrfs allocate inodes dynamically and avoid this specific failure.
A useful safety option is the dry run. mkfs.ext4 -n shows what would be created, including the backup superblock locations, without writing anything, and those locations help later recovery with fsck if the primary superblock is damaged.
Where mkfs fits among related tools
mkfs is one step in the storage provisioning chain, and confusing it with neighboring tools is a frequent source of mistakes. Partitioning tools define where a filesystem lives, mkfs creates it, and mount attaches it to the directory tree.
| Tool | Purpose | Relation to mkfs |
|---|---|---|
| fdisk, parted | Create partition tables and partitions | Runs before mkfs |
| LVM tools | Create logical volumes from physical disks | Provides devices for mkfs |
| mkfs | Writes a new empty filesystem | The formatting step itself |
| mount | Attaches a filesystem at a mount point | Runs after mkfs |
| fsck | Checks and repairs an existing filesystem | Never creates one |
| tune2fs, xfs_admin | Change labels and some settings later | Adjusts what mkfs created |
Some properties can be adjusted after creation: tune2fs changes the ext4 label, reserved percentage and certain features, and resize2fs or xfs_growfs enlarge a filesystem. Block size and, on ext4, the total inode count cannot be changed this way.
Using mkfs safely in practice
Safe use of mkfs starts with identifying the target device unambiguously. Device names such as /dev/sdb can change between boots, so administrators confirm size, model and existing contents with lsblk -f and blkid immediately before formatting, and prefer stable paths under /dev/disk/by-id/.
- Confirm the device with
lsblk -f, checking size and current filesystem. - Make sure nothing is mounted from that device, including swap.
- Run the specific builder, for example
mkfs.ext4 -L backup /dev/sdb1. - Record the new UUID from
blkidand add it to fstab. - Mount and test with
mount -abefore rebooting.
Current builders refuse to overwrite a device that is mounted or already carries a known signature unless a force option is given. This protection is helpful, but it is not a backup strategy: an administrator who adds -f out of habit removes the last safeguard.
Common mkfs mistakes and their consequences
Most mkfs problems are human errors in target selection or parameters, not software faults. The table below pairs typical symptoms with causes and remedies.
| Symptom | Likely cause | Fix |
|---|---|---|
| Data on another disk vanished | Wrong device name formatted | Stop writes and attempt recovery from backup |
| No space left with free blocks | Too few inodes on ext4 | Reformat with a lower inode ratio |
| Partition table destroyed | Whole disk formatted instead of partition | Restore the table, then check the data |
| Device or resource busy | Target still mounted or in use | Unmount it or disable swap first |
| Slow writes on RAID | Stripe geometry not set | Recreate with correct alignment options |
Formatting rewrites metadata rather than every data block, so file contents may partly survive and forensic tools can sometimes recover them. That is a reason to treat mkfs as unsuitable for secure erasure; tools such as blkdiscard or device-level secure erase are designed for that purpose.
The short version
A new disk is like an empty warehouse with no shelves, labels or inventory list. mkfs builds the shelving and the catalog so that Linux knows where each file can be stored and found later.
The catch is that building new shelves throws away the old catalog. If mkfs is pointed at a disk that already holds files, those files become unreachable, so it pays to double-check which disk is selected.
Where it makes a difference
A systems administrator adds a 4 TB disk to a file server that will store several million small thumbnail images. Using lsblk -f, the administrator confirms the new disk is /dev/sdc, empty and unmounted, then creates one partition with parted.
Knowing that the default ext4 inode ratio could run out with so many small files, the administrator runs mkfs.ext4 -L thumbs -i 8192 -m 1 /dev/sdc1, which doubles the inode count compared with the default and reduces reserved space to 1 percent. The UUID goes into fstab and the volume is mounted at /srv/thumbs.
Months later the volume holds nine million files at 60 percent capacity, with inodes still well below their limit, avoiding the out-of-space errors seen on an older server formatted with defaults.