$linuxjunkies
>

mkfs(8)

Create a filesystem on a block device or partition.

UbuntuDebianFedoraArch

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

FlagWhat it does
-t TYPESpecify filesystem type (ext4, ext3, xfs, btrfs, vfat, etc.); defaults to ext2 if not specified
-FForce creation without prompting for confirmation, even on non-empty devices
-vProduce verbose output showing filesystem creation details
-L LABELSet filesystem label (name) for the new filesystem
-m RESERVEDSet percentage of filesystem blocks reserved for root user (ext4 only, default 5%)
-b BLOCK_SIZESpecify block size in bytes (typically 1024, 2048, or 4096)
-N INODESSpecify the number of inodes to create in the filesystem
-U UUIDSet the UUID (Universally Unique Identifier) for the filesystem
-qQuiet mode; suppress most output messages

Examples

Create an ext4 filesystem on /dev/sda1 partition

sudo mkfs -t ext4 /dev/sda1

Create ext4 filesystem with label 'mydata' (direct invocation of mkfs.ext4)

sudo mkfs.ext4 -L mydata /dev/sdb1

Force creation of XFS filesystem on NVMe drive partition

sudo mkfs -t xfs -f /dev/nvme0n1p2

Create FAT32 filesystem suitable for USB drives or external media

sudo mkfs -t vfat -F 32 /dev/sdc1

Create ext4 with 1% reserved space and label 'backup' on external drive

sudo mkfs.ext4 -m 1 -L backup /dev/sdd1

Create Btrfs filesystem for copy-on-write and snapshot capabilities

mkfs -t btrfs /dev/sde1

Create ext4 with specific UUID for mounting by UUID in /etc/fstab

sudo mkfs -t ext4 -U 550e8400-e29b-41d4-a716-446655440000 /dev/sdf1

Related commands