mkfs(8)
Create a filesystem on a block device or partition.
Synopsis
mkfs [OPTIONS] [-t TYPE] DEVICE [SIZE]Description
mkfs is used to build a Linux filesystem on a device, usually a hard disk partition. DEVICE is typically a device file like /dev/sda1, /dev/nvme0n1p1, or a loop device. SIZE is optional and specifies the number of blocks.
mkfs is essentially a front-end that calls filesystem-specific tools like mkfs.ext4, mkfs.xfs, mkfs.btrfs, etc. The actual filesystem creation behavior depends on the underlying utility for your chosen filesystem type.
Common options
| Flag | What it does |
|---|---|
-t TYPE | Specify filesystem type (ext4, ext3, xfs, btrfs, vfat, etc.); defaults to ext2 if not specified |
-F | Force creation without prompting for confirmation, even on non-empty devices |
-v | Produce verbose output showing filesystem creation details |
-L LABEL | Set filesystem label (name) for the new filesystem |
-m RESERVED | Set percentage of filesystem blocks reserved for root user (ext4 only, default 5%) |
-b BLOCK_SIZE | Specify block size in bytes (typically 1024, 2048, or 4096) |
-N INODES | Specify the number of inodes to create in the filesystem |
-U UUID | Set the UUID (Universally Unique Identifier) for the filesystem |
-q | Quiet mode; suppress most output messages |
Examples
Create an ext4 filesystem on /dev/sda1 partition
sudo mkfs -t ext4 /dev/sda1Create ext4 filesystem with label 'mydata' (direct invocation of mkfs.ext4)
sudo mkfs.ext4 -L mydata /dev/sdb1Force creation of XFS filesystem on NVMe drive partition
sudo mkfs -t xfs -f /dev/nvme0n1p2Create FAT32 filesystem suitable for USB drives or external media
sudo mkfs -t vfat -F 32 /dev/sdc1Create ext4 with 1% reserved space and label 'backup' on external drive
sudo mkfs.ext4 -m 1 -L backup /dev/sdd1Create Btrfs filesystem for copy-on-write and snapshot capabilities
mkfs -t btrfs /dev/sde1Create ext4 with specific UUID for mounting by UUID in /etc/fstab
sudo mkfs -t ext4 -U 550e8400-e29b-41d4-a716-446655440000 /dev/sdf1