Linux Commands

How to Format a Drive in Linux

Formatting a drive is necessary whenever you are trying to erase data on a drive or partition or to create a new partition. Before formatting a partition or drive, it is strongly recommended to make sure that there is nothing important there, as formatting may erase the data for good.

This guide shows you how to format a drive in Linux.

Formatting a Drive in Linux

There are two primary ways of formatting a drive in Linux: using the CLI and using the GUI. For general users, using a GUI tool may be more comfortable, whereas advanced or professional users may find the CLI method better suits them.

Either way, performing a disk format requires root access or sudo privileges. However, in certain situations, a different user can perform drive format if there is write permission for that drive. This article was written with the assumption that you have root access to your system.

The drive formatting process can be a bit tricky. To use the device storage, a drive must have a partition table with or without partitions. The partitions will allow the OS to access the storage. By formatting the drive, we are formatting the partition. If there are multiple partitions, then you have to perform the formatting process for all of them.

Formatting a Partition using the GUI Method

For managing disks and partitions (and related functions), GParted is the best option. GParted is a free and open-source tool used for managing disk partitions. This tool comes with tons of features and support for numerous file systems.

There are two ways to use GParted. You can install GParted on the running system or use the bootable image to perform the disk format. Both methods come with their own pros and cons. The good part is, whichever method you follow, the UI of GParted works the same.

First, we will show you how to install GParted onto your system. Depending on the Linux distro that you are running on your system, use the appropriate one.

For Debian/Ubuntu and derivatives:

$ sudo apt install -y gparted

For Fedora and derivatives:

$ sudo yum install gparted

For openSUSE and derivatives:

$ sudo zypper install gparted

To use GParted from the boot, download the GParted bootable ISO here. You can also make a bootable CD, DVD, or USB flash drive. Check out how to make a bootable USB flash drive on Linux here. Once you have prepared the system, boot into the CD, DVD, or USB flash drive.

From this point on, GParted behaves the same. For convenience, I will be demonstrating using GParted installed on Ubuntu.

Launch GParted, and it will ask for the root password.

From the top-right corner, select the device on which the operation is to be performed.

Next, you must decide the target partition. For an in-depth guide on how to create and manage partitions using GParted, check out how to use GParted here. In this case, the target partition is the /dev/sda5 partition.

As you can see, the partition is currently mounted. Before performing any action, the partition must be unmounted. Right-click and select “Unmount.”

Now, the partition is ready to be formatted. If the device is a USB flash drive, then file systems like FAT32, NTFS, and EXT4 are generally the best option. If the device is an HDD, then it is better to go for EXT4. You can also go for a different format if there is a need for a specific file system. In my case, I will right-click and select “Format to” >> “fat32.”

An interesting feature of GParted is that it does not write the changes to the drive instantly. This way, even if you misconfigure the drive, you can easily discard the changes. To make the changes permanent, click “Apply All Operations.”

GParted will now ask you for confirmation. In this example, after performing the formatting, the partition will lose all its data. Click “Apply” to confirm.

Voila! The partition has been formatted successfully!

Formatting a Partition Using the CLI method

This method is relatively shorter than the previous one. However, this method is only recommended for advanced users, as it comes with a higher chance of damage to the system. This method is less failsafe than GParted, so you must be super careful.

Connect the device to the computer. By default, most Linux distros will mount all the partitions of the device. Assuming it hosts a single partition, it will be mounted automatically. Check out the list of mounted filesystems below.

$ df -h

It is not allowed to format a partition that is currently mounted. To unmount the partition, run the following command.

$ sudo umount <target_partition>

Now, you can format the partition with your desired filesystem. Run the command that suits your needs.

$ sudo mkfs.ext4 <target_partition>

$ sudo mkfs.ntfs <target_partition>

$ sudo mkfs.vfat <target_partition>

$ sudo mkfs.xfs -f <target_partition>

Final Thoughts

Formatting a drive in Linux is not complicated. All it requires is the willingness to focus and learn a few new things. Once mastered, you can use the methods discussed in this article on any Linux distro.

Partition formatting is not the only thing Linux offers. Using the built-in tools that Linux comes with, you can manipulate drive partitions. To learn more, check out how to use the Linux mount command and Linux umount command.

About the author

Sidratul Muntaha

Student of CSE. I love Linux and playing with tech and gadgets. I use both Ubuntu and Linux Mint.