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.
- 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.
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.
lsblk command without additional options does not display information about the devices’ file systems.
To display a list containing file system information, add the
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.
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:
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:
The terminal prints out a list of block devices.
3. Locate the preferred partition and confirm that it uses the ext4 file system.
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.
The expected output is:
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:
3. Locate the preferred partition and confirm that it uses the NFTS file system.
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]
[mountpoint] with the preferred mount point (example:
There is no output if the process completes successfully.
3. Verify if the partition is mounted using the following command:
The expected output is:
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:
Their main features and differences are:
|File System||Supported File Size||Compatibility||Ideal Usage|
|FAT32||up to 4 GB||Windows, Mac, Linux||For maximum compatibility|
|NTFS||16 EiB – 1 KB||Windows, Mac (read-only), most Linux distributions||For internal drives and Windows system file|
|Ext4||16 GiB – 16 TiB||Windows, 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.
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.