Language
日本語
English

Caution

JavaScript is disabled in your browser.
This site uses JavaScript for features such as search.
For the best experience, please enable JavaScript before browsing this site.

Linux & Mac & Bash Command Dictionary

  1. Home
  2. Linux & Mac & Bash Command Dictionary
  3. mkfs (Creating Filesystems)

mkfs (Creating Filesystems)

mkfs is a family of Linux commands for creating filesystems. They format a partition or block device so it can be used to store files. By choosing among the three major filesystem types — ext4, xfs, and btrfs — you can pick the best option for your workload, whether that is a general-purpose server, a high-throughput database, or an environment that requires snapshots. Once created, a filesystem can be temporarily mounted with the mount command, and made persistent across reboots by adding an entry to /etc/fstab.

Syntax

# -----------------------------------------------
#  Creating a filesystem (mkfs)
# -----------------------------------------------

# mkfs.ext4 {device}
#   → Creates an ext4 filesystem
#   → A standard, general-purpose filesystem
#   Example: sudo mkfs.ext4 /dev/sdb1

# mkfs.ext4 -L {label} {device}
#   → Creates an ext4 filesystem with a volume label
#   Example: sudo mkfs.ext4 -L data01 /dev/sdb1

# mkfs.xfs {device}
#   → Creates an xfs filesystem
#   → Optimized for large files and high I/O; the default on RHEL-based systems
#   Example: sudo mkfs.xfs /dev/sdb1

# mkfs.xfs -L {label} {device}
#   → Creates an xfs filesystem with a volume label
#   Example: sudo mkfs.xfs -L data01 /dev/sdb1

# mkfs.btrfs {device}
#   → Creates a btrfs filesystem
#   → Supports snapshots, subvolumes, and transparent compression
#   Example: sudo mkfs.btrfs /dev/sdb1

# mkfs.btrfs -L {label} {device}
#   → Creates a btrfs filesystem with a volume label
#   Example: sudo mkfs.btrfs -L data01 /dev/sdb1

# -----------------------------------------------
#  Mounting and unmounting (mount / umount)
# -----------------------------------------------

# mount {device} {mount point}
#   → Mounts a filesystem at a directory
#   Example: sudo mount /dev/sdb1 /mnt/data

# mount -t {filesystem type} {device} {mount point}
#   → Mounts a filesystem with the type specified explicitly
#   Example: sudo mount -t ext4 /dev/sdb1 /mnt/data
#   Example: sudo mount -t xfs /dev/sdb1 /mnt/data

# mount -o {options} {device} {mount point}
#   → Mounts a filesystem with the given mount options
#   Example: sudo mount -o ro /dev/sdb1 /mnt/data        (read-only)
#   Example: sudo mount -o remount,rw /dev/sdb1 /mnt/data (remount as read-write)

# mount
#   → Lists all currently mounted filesystems

# umount {mount point or device}
#   → Unmounts a filesystem
#   Example: sudo umount /mnt/data
#   Example: sudo umount /dev/sdb1

# -----------------------------------------------
#  /etc/fstab format
# -----------------------------------------------

# {device}  {mount point}  {FS type}  {options}  {dump}  {pass}
#
#  Field 1 (device) : Device file, UUID, or LABEL
#  Field 2 (mount point) : Directory path where the filesystem is mounted
#  Field 3 (FS type) : ext4 / xfs / btrfs / swap, etc.
#  Field 4 (options) : defaults / ro / noatime / nofail, etc.
#  Field 5 (dump) : Whether to include in dump backups (usually 0)
#  Field 6 (pass) : fsck check order (root = 1, others = 2 or 0)
#
#  Example (UUID-based):
#  UUID=a1b2c3d4-e5f6-7890-abcd-ef1234567890 /mnt/data  ext4  defaults,nofail  0  2

Command reference

Command / FieldDescription
mkfs.ext4 {device}Creates an ext4 filesystem. It is the standard choice for general-purpose use and the default on Ubuntu and Debian. Journaling makes recovery after a crash straightforward.
mkfs.xfs {device}Creates an xfs filesystem. It performs well with large files and high-concurrency I/O, and is the default on RHEL-based Linux distributions. An existing xfs filesystem can be expanded online, but cannot be shrunk.
mkfs.btrfs {device}Creates a btrfs filesystem. It is a next-generation filesystem with built-in snapshots, subvolumes, transparent compression, and RAID support. It is the default on Fedora and openSUSE.
mount -t {type} {device} {mount point}Mounts a device with the filesystem type specified explicitly. The type can be omitted for auto-detection, but specifying it avoids misidentification.
umount {mount point}Unmounts a mounted filesystem. If a process is actively using the target directory, you will get a "device is busy" error. Use lsof +D {mount point} to find the processes accessing it.
mount -aMounts all entries listed in /etc/fstab. Use this to verify that a fstab edit is correct before rebooting.
blkid {device}Displays the UUID, label, and filesystem type of a device. Use this to get the UUID when writing a fstab entry.
fstab field 1 (device)Specifies the device to mount. Device paths such as /dev/sdb1 can change after a reboot, so using UUID=... or LABEL=... is recommended.
fstab field 2 (mount point)Specifies the directory path where the filesystem will be mounted. The directory must be created with mkdir before mounting.
fstab field 3 (FS type)Specifies the filesystem type. Accepted values include ext4, xfs, btrfs, swap, and vfat. Use auto to let the system detect the type automatically.
fstab field 4 (options)Specifies mount options as a comma-separated list. defaults (rw / suid / exec / auto / nouser / async) is the typical starting point. nofail allows the system to continue booting even if the device is not present.
fstab field 5 (dump)Indicates whether the filesystem should be included in backups by the legacy dump command. On modern systems this is normally set to 0 (disabled).
fstab field 6 (pass)Specifies the order in which fsck checks the filesystem at boot. Set to 1 for the root filesystem, 2 for additional disks, and 0 to skip the check.

Examples

Creating and mounting an ext4 filesystem
# -----------------------------------------------
#  Format a new disk /dev/sdb with ext4 and mount it persistently
#  (Scenario: a disk for storing surveillance data for PSB Division 1)
# -----------------------------------------------

# Check the current state of the device
# Confirm that /dev/sdb has no partitions yet
sudo fdisk -l /dev/sdb

# Create a partition (use fdisk to create partition /dev/sdb1)
# See the disk_partition page for details
sudo fdisk /dev/sdb

# Create an ext4 filesystem
# Use -L to assign the volume label "psychopass-data"
sudo mkfs.ext4 -L psychopass-data /dev/sdb1

# Create the mount point directory
sudo mkdir -p /mnt/psychopass-data

# Temporarily mount the filesystem to verify it works
sudo mount /dev/sdb1 /mnt/psychopass-data

# Confirm the mount succeeded
df -h /mnt/psychopass-data

# Get the UUID to use in /etc/fstab for persistent mounting
# UUID uniquely identifies the device across reboots, unlike /dev/sdb1
sudo blkid /dev/sdb1

Run the following command:

$ sudo blkid /dev/sdb1
/dev/sdb1: LABEL="psychopass-data" UUID="c7a94e12-3f8b-4d02-9e5a-1b8d06f72c34" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="8e3d21a0-01"

The following example demonstrates this:

# Append the mount entry to /etc/fstab
# Use UUID to identify the device (device names can change)
# nofail prevents the boot process from halting if the disk is missing
echo 'UUID=c7a94e12-3f8b-4d02-9e5a-1b8d06f72c34 /mnt/psychopass-data  ext4  defaults,nofail  0  2' | sudo tee -a /etc/fstab

# Unmount and remount via fstab
sudo umount /mnt/psychopass-data

# Mount all fstab entries (any errors in fstab will surface here)
sudo mount -a

# Final check to confirm the filesystem is mounted
df -h /mnt/psychopass-data

Run the following command:

$ df -h /mnt/psychopass-data
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1       197G  1.6G  186G   1% /mnt/psychopass-data
Creating an xfs filesystem (RHEL-based systems)
# -----------------------------------------------
#  Format /dev/sdc1 with xfs and mount it persistently
#  (Scenario: a high-I/O disk for MWPSB crime coefficient analysis logs)
# -----------------------------------------------

# Create an xfs filesystem
# xfs is the default format on RHEL-based systems (AlmaLinux / Rocky Linux)
sudo mkfs.xfs -L dominator-log /dev/sdc1

# Create the mount point
sudo mkdir -p /mnt/dominator-log

# Mount the filesystem, specifying xfs as the type explicitly
sudo mount -t xfs /dev/sdc1 /mnt/dominator-log

# Get the UUID and append it to fstab
sudo blkid /dev/sdc1

Run the following command:

$ sudo blkid /dev/sdc1
/dev/sdc1: LABEL="dominator-log" UUID="f2e85b31-7c4a-48d9-b16e-9a2f0c83e471" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="1d7c9b44-01"

The following example demonstrates this:

# Append to fstab (xfs supports online expansion but cannot be shrunk)
echo 'UUID=f2e85b31-7c4a-48d9-b16e-9a2f0c83e471 /mnt/dominator-log  xfs  defaults,nofail  0  2' | sudo tee -a /etc/fstab

# Remount via fstab and verify
sudo umount /mnt/dominator-log
sudo mount -a
mount | grep dominator-log

Run the following command:

$ mount | grep dominator-log
/dev/sdc1 on /mnt/dominator-log type xfs (rw,relatime,attr2,inode64,logbufs=8,logbsize=32k,noquota)
Creating a btrfs filesystem (with snapshot support)
# -----------------------------------------------
#  Format /dev/sdd1 with btrfs and mount it with subvolumes
#  (Scenario: case file storage and snapshot management for the Public Safety Bureau)
# -----------------------------------------------

# Create a btrfs filesystem
sudo mkfs.btrfs -L sibyl-archive /dev/sdd1

# Create the mount point and mount the filesystem
sudo mkdir -p /mnt/sibyl-archive
sudo mount /dev/sdd1 /mnt/sibyl-archive

# Create btrfs subvolumes
# Snapshots can be managed independently per subvolume
sudo btrfs subvolume create /mnt/sibyl-archive/@data
sudo btrfs subvolume create /mnt/sibyl-archive/@snapshots

# List the btrfs subvolumes
sudo btrfs subvolume list /mnt/sibyl-archive

Run the following command:

$ sudo btrfs subvolume list /mnt/sibyl-archive
ID 256 gen 7 top level 5 path @data
ID 257 gen 8 top level 5 path @snapshots

The following example demonstrates this:

# Get the UUID and append to fstab
# Use the subvol= option to specify which subvolume to mount
sudo blkid /dev/sdd1

Run the following command:

$ sudo blkid /dev/sdd1
/dev/sdd1: LABEL="sibyl-archive" UUID="8a3d6f09-c21e-4b77-a9e3-5c0871d4b293" UUID_SUB="d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f80" BLOCK_SIZE="4096" TYPE="btrfs" PARTUUID="2a4b6c8e-01"

The following example demonstrates this:

# Unmount and remount using the fstab entry with the subvolume specified
sudo umount /mnt/sibyl-archive

# Mount the @data subvolume at /mnt/sibyl-archive
echo 'UUID=8a3d6f09-c21e-4b77-a9e3-5c0871d4b293 /mnt/sibyl-archive  btrfs  defaults,subvol=@data,compress=zstd,nofail  0  0' | sudo tee -a /etc/fstab
sudo mount -a

# Show detailed information about the btrfs filesystem
sudo btrfs filesystem show /mnt/sibyl-archive

Run the following command:

$ sudo btrfs filesystem show /mnt/sibyl-archive
Label: 'sibyl-archive'  uuid: 8a3d6f09-c21e-4b77-a9e3-5c0871d4b293
	Total devices 1 FS bytes used 1.02MiB
	devid    1 size 500.00GiB used 3.02GiB path /dev/sdd1

Overview

The mkfs commands and mount are the fundamental operations for putting storage to use on Linux. Choosing the right filesystem type for the job is important. ext4 has a long track record and is the default on Debian and Ubuntu, making it a solid choice for general-purpose servers. xfs excels at large-file and high-concurrency I/O workloads and is the default on RHEL-based systems, making it well-suited for database and storage servers. btrfs offers advanced features such as snapshots, subvolumes, and transparent compression, enabling backup strategies to be built directly into the storage layer. Before creating a filesystem, always prepare a partition first using partition management (fdisk / parted). For flexible management of large disks, combining filesystems with LVM (Logical Volume Management) is also effective. After mounting, use the df / du commands to check disk usage. An incorrect /etc/fstab entry can prevent the system from booting, so always run mount -a to verify the configuration before rebooting.

If you find any errors or copyright issues, please .