How to Format Disk Partitions in Linux

December 2, 2020

Introduction

A disk partition must be formatted and mounted before use. The formatting process can also be done for several other reasons, such as changing the file system, fixing errors, or deleting all data.

In this tutorial, you will learn how to format and mount disk partitions in Linux using ext4, FAT32, or NTFS file system.

How to Format Disk Partitions in Linux

Prerequisites

  • A system running Linux
  • A user account with sudo or root privileges
  • Access to a terminal window / command line (Activities > Search > Terminal)

Checking the Partitions

Before formatting, locate a partition you wish to format. To do so, run the lsblk command that displays block devices. Block devices are files that represent devices such as hard drives, RAM disks, USB drives, and CD/ROM drives.

lsblk

The terminal prints out a list of all block devices as well as information about them:

  • NAME – Device names
  • MAJ:MIN – Major or minor device numbers
  • RM – Whether the device is removable (1 if yes, 0 if no)
  • SIZE – The size of the device
  • RO – Whether the device is read-only
  • TYPE – The type of the device
  • MOUNTPOINT – Device’s mount point

We will use the /dev/sdb1 partition as an example.

Locating partitions with lsblk command.

The lsblk command without additional options does not display information about the devices’ file systems.

To display a list containing file system information, add the -f option:

lsblk -f

The terminal prints out the list of all block devices. The partitions that do not contain information on the file system in use are non-formatted partitions.

Locating non-formatted partitions with lsblk -f command.

Note: Consider learning how to create partitions in Linux.


Formatting Disk Partition in Linux

There are three ways to format disk partitions using the mkfs command, depending on the file system type:

  • ext4
  • FAT32
  • NTFS

The general syntax for formatting disk partitions in Linux is:

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

Formatting Disk Partition with ext4 File System

1. Format a disk partition with the ext4 file system using the following command:

sudo mkfs -t ext4 /dev/sdb1

2. Next, verify the file system change using the command:

lsblk -f

The terminal prints out a list of block devices.

3. Locate the preferred partition and confirm that it uses the ext4 file system.

The process of formatting disk partition using the ext4 file system in Linux.

Formatting Disk Partition with FAT32 File System

1. To format a disk with a FAT32 file system, use:

sudo mkfs -t vfat /dev/sdb1

2. Again, run the lsblk command to verify the file system change and locate the preferred partition from the list.

lsblk -f

The expected output is:

Formatting disk partition using FAT32 file system in Linux.

Formatting Disk Partition with NTFS File System

1. Run the mkfs command and specify the NTFS file system to format a disk:

sudo mkfs -t ntfs /dev/sdb1

The terminal prints a confirmation message when the formatting process completes.

2. Next, verify the file system change using:

lsblk -f

3. Locate the preferred partition and confirm that it uses the NFTS file system.

Formatting a partition with NTFS file system in Linux.

Mounting the Disk Partition in Linux

Before using the disk, create a mount point and mount the partition to it. A mount point is a directory used to access data stored in disks.

1. Create a mount point by entering:

sudo mkdir -p [mountpoint]

2. After that, mount the partition by using the following command:

sudo mount -t auto /dev/sdb1 [mountpoint]

Note: Replace [mountpoint] with the preferred mount point (example:/usr/media).


There is no output if the process completes successfully.

The process of creating mount point and mounting.

3. Verify if the partition is mounted using the following command:

lsblk -f

The expected output is:

Verifying formatting and mounting partition process.

Understanding the Linux File System

Choosing the right file system before formatting a storage disk is crucial. Each type of file system has different file size limitations or different operating system compatibility.

The most commonly used file systems are:

  • FAT32
  • NTFS
  • ext4

Their main features and differences are:

File SystemSupported File SizeCompatibilityIdeal Usage
FAT32up to 4 GBWindows, Mac, LinuxFor maximum compatibility
NTFS16 EiB – 1 KBWindows, Mac (read-only), most Linux distributionsFor internal drives and Windows system file
Ext416 GiB – 16 TiBWindows, Mac, Linux (requires extra drivers to access)For files larger than 4 GB

Note: Refer to our Introduction to Linux File System article to learn more about the evolution and features of different Linux file systems.


Conclusion

After following this tutorial, you should be able to format and mount a partition in Linux in various file systems. Partition manipulation is essential for efficient data management, and next, we recommend learning how to delete a partition in Linux.

Nevena Pavlicic
Nevena Pavlicic is an aspiring Technical Writer at PhoenixNAP with experience in writing user manuals and blog posts. She has always enjoyed researching and building knowledge on cutting edge technologies, but she is also passionate about simplifying complex concepts.
Next you should read
How to Format USB Drives in Linux
November 19, 2020

USB formatting is done for several reasons, such as deleting data or changing the file system. In this...
Read more
Introduction to the Linux File System
October 21, 2020

A file system is a set of processes that controls how, where and when data is stored and retrieved from...
Read more
How to Delete Partition in Linux
September 30, 2020

Creating and deleting partitions in Linux is common because users must structure storage devices (USB and...
Read more
How to Use the sudo Command in Linux
August 18, 2020

sudo stands for SuperUser DO, and it is used to temporarily elevate privileges in Linux. This guide will show...
Read more
  • © 2021 Copyright phoenixNAP | Global IT Services. All Rights Reserved.