On Unix-like operating systems, the mkfs command creates and builds a file system.

This page describes the Linux version of mkfs.

Description

mkfs is used to build a Linux file system on a device, usually a hard disk partition. The device argument is either the device name (e.g., /dev/hda1, /dev/sdb2), or a regular file containing the file system. The size argument is the number of blocks to be used for the file system.

  • Description
  • Syntax
  • Examples
  • Related commands
  • Linux commands help

The exit status returned by mkfs is 0 on success and 1 on failure.

In actuality, mkfs is a front-end for the various file system builders (mkfs.fstype) available under Linux. The filesystem-specific builder is searched for in many directories, like perhaps /sbin, /sbin/fs, /sbin/fs.d, /etc/fs, /etc (the precise list is defined at compile time, but at least contains /sbin and /sbin/fs), and finally in the directories listed in the PATH environment variable. Please see your filesystem-specific builder manual pages for further details.

Syntax

mkfs [options] [-t type fs-options] device [size]

Options

Examples

mkfs -t ext2 /dev/fd0

The example above would create an ext2 file system on a floppy diskette in the first floppy drive.

fdisk — A disk partitioning utility.fsck — Check and repair a Linux file system.losetup — Set up and control loop devices.