How to Format a USB Drive in Ubuntu Terminal?

Formatting a USB drive using the Ubuntu terminal is a quick and efficient way to wipe data or prepare a flash drive for a new operating system. This process primarily relies on the mkfs (make filesystem) command, which allows you to format partitions into various filesystems like FAT32, NTFS, or ext4. Before running the format command, you must use tools like lsblk or df to correctly identify your USB drive’s identifier, ensuring you do not accidentally overwrite your primary system data.

Step 1: Identify Your USB Drive

Before formatting, you need to find the specific identifier assigned to your USB drive. Plug in your USB drive and open your terminal (Ctrl + Alt + T), then run the following command:

lsblk

This command lists all block devices connected to your system. Look for your USB drive by matching its storage size. It will typically be listed as something like /dev/sdb or /dev/sdc, with the specific partition you want to format labeled with a number, such as /dev/sdb1.

Step 2: Unmount the USB Partition

Ubuntu often automatically mounts USB drives when they are plugged in. You cannot format a partition while it is actively mounted. To unmount the partition, use the umount command followed by your specific partition identifier:

sudo umount /dev/sdb1

Step 3: Format the Drive Using the mkfs Command

Once unmounted, you can use the mkfs command to format the drive. The exact command depends on the filesystem type you want to use.

sudo mkfs.vfat -F 32 /dev/sdb1
sudo mkfs.ntfs /dev/sdb1
sudo mkfs.ext4 /dev/sdb1

Optional: Label Your USB Drive During Formatting

If you want to give your USB drive a specific name (label) so it is easily recognizable when plugged into a computer, you can add a label flag to the command.

sudo mkfs.vfat -F 32 -n MyStorage /dev/sdb1
sudo mkfs.ext4 -L LinuxDrive /dev/sdb1

Once the terminal outputs a success message and returns to the standard prompt, the formatting process is complete, and your USB drive is ready for use.