Building File Systems

The mkfs command syntax enables you to build a file system on a block device:

sudo mkfs [options] device

Typically, the -t fstype and -L label options are used with the mkfscommand. The following example builds an ext4 file system with the label Project:

sudo mkfs -t ext4 -L Projects /dev/sdb1

If you don't specify the file system type, an ext2 file system is created by default.

You can also omit -t fstype and instead use the appropriate full mkfs.<extension> command as listed in /sbin. The following command produces the same result as the previous command:

sudo mkfs.ext4 -L Projects /dev/sdb1

To display the file system type, use the blkid command, for example:

sudo blkid /dev/sdb1

The output of the previous command would be similar to the following:

/dev/sdb1: UUID="ad8113d7-b279-4da8-b6e4-cfba045f66ff" BLOCK_SIZE="512" TYPE="ext4" 
  PARTUUID="PARTUUID="6a0cf5e9-09e5-40cf-ab47-3166e1c60f24" LABEL="Projects"

Each file system type supports several features that you can enable or disable by specifying more options with either the mkfs command format or the full mkfs.<extension> command. For example, you can use the -J option to specify the size and location of the journal that's used by the ext* file system types.

For more information, see the blkid(8), mkfs(8), and mkfs.fstype(8) manual pages.