Format a USB drive in Ubuntu

Published: October 31, 2022

Format a USB drive in Ubuntu

In this article, we cover how to format a USB drive in Ubuntu. There are various GUI tools like GParted, GNOME Disk Utility etc. which can be used to format a USB drive. Here, we focus mainly on utilizing various command-line tools to get the desired outcome.

A USB drive would have one or more partition. These partitions can be formatted, with different filesystem types like ext4, NTFS, FAT etc. But, before that we need to identify the USB drive.

Note: Following operations require superuser privileges. In case you don't have one then, we advise you to contact your System Administrator for assistance.

IMPORTANT - Apart from that, formatting a USB drive would mean all the data stored in the partition we format would be erased. If we have just one partition on our USB drive then, that would mean everything stored in USB drive is erased. So, we just have to keep a backup. Also, it is crucial to identify the USB drive which we want to format. If we format a drive which we didn't intend to then, data stored in the drive would be erased. Although there are numerous data recovery tools available but still not everything would be recovered.

Identify the USB drive

Use the following command to identify the USB drive -

sudo fdisk -l

It would also show us the number of partitions we have.

Format a USB drive in Ubuntu

To format a USB drive partition with filesystem, we can use mkfs command-line utility.

sudo mkfs -t <filesystem_type> <drive_partition>

For example, the partition we wanted to format was - /dev/sdb2 and filesystem type we chose - ext4

sudo mkfs -t ext4  /dev/sdb2
This is just to show you how things should be done. The <drive_partition> would be different for you.

Once we issue the command, it would prompt us whether to format the current filesystem. If you are fine with it then, proceed.

If you get an error -

<drive_partition> is mounted; will not make a filesystem here!

Then, use umount command-line utility to unmount that partition.

sudo umount <drive_partition>

In conclusion, we have covered how to format a USB drive in Ubuntu.