Categories: Ubuntu

How to Format a USB on the Ubuntu Terminal

When you have your USB drive, you may want to format it for different reasons such as changing your file system or wiping all the existing data, especially if you want to clean an infected drive. Unlike other operating systems, Linux offers a convenient way of formatting a USB drive graphically and via the command line.

This guide covers the step-by-step process of formatting a USB drive via the command line. We will give the commands to follow while showing an example for demonstration purposes. That way, you can conveniently follow along and format your USB drive.

Step-by-Step Guide to Format a USB on the Ubuntu Terminal

Sponsored

When using Ubuntu, you can quickly format your USB drive with straightforward steps that anyone can get comfortable using. Note that formatting your USB will erase all its contents. If you don’t want to lose any data, create a backup before you start the formatting. Also, ensure that you connected the USB drive to the ports on your computer, then proceed as follows.

First, we must locate where the USB drive is mounted on our Ubuntu. You can use the df command to print all the mounted file systems. Adding the -h option makes the command to print in a human-readable format.

$ df -h

In our case, the target USB drive is the /dev/sdb1 and is in the /media/kyle/k.

Alternatively, you can use the lsblk command and filter the output using the grep command to get the mounted USB drive.

$ lsblk | grep media

Before we format the USB drive, we must unmount it since you can’t format any mounted disk on a Linux system.

To unmount the USB drive, use the umount command followed by the mounted USB drive.

$ sudo umount /dev/sdb1

Once you unmount the USB drive, verify the mounted file systems to verify that we now have the USB drive unmounted.

You are now ready to format your USB drive, depending on the file system that you want to use including FAT32, NTFS, etc.

Sponsored

For FAT32, use the following command:

$ sudo mkfs.vfat /dev/sdb1

For NTFS, use the following command:

$ sudo mkfs.ntfs /dev/sdb1

Use the following command to use the EXT4 file system:

$ sudo mkfs.ext4 /dev/sdb1

In our case, we format the USB drive as FAT32 to make it usable with any operating system.

Your USB drive is now formatted. We can verify it using the fsck command as presented in the following:

$ sudo fsck /dev/sdb1

A formatted USB drive contains no files, like in the previous output, where our /dev/sdb1 displays that it has zero files which confirms that we managed to format it successfully.

You now have your USB drive formatted to use for your activities. If the drive is infected, formatting it cleans up all its clusters, and you now have a clean and usable USB drive.

Conclusion

When you want to format a USB drive on Ubuntu using your terminal, there are different steps that you must follow. First, locate the mounted file system for your USB drive. Next, unmount the USB drive file system and proceed to format it depending on the format file system in your case. Lastly, verify that your USB has been formatted.

Ubuntu Server Admin

Recent Posts

Ubuntu Weekly Newsletter Issue 890

Welcome to the Ubuntu Weekly Newsletter, Issue 890 for the week of April 27 –…

3 hours ago

Ubuntu IoT Day in Singapore – Unlock compliant and scalable innovation in edge AI

Singapore | May 27, 2025 | Full-day event How do you build robust, performant edge…

11 hours ago

Kolla Ansible OpenStack Installation (Ubuntu 24.04)

Kolla Ansible provides production-ready containers (here, Docker) and deployment tools for operating OpenStack clouds. This…

3 days ago

Canonical announces first Ubuntu Desktop image for Qualcomm Dragonwing™ Platform with Ubuntu 24.04

This public beta enables the full Ubuntu Desktop experience on the Qualcomm Dragonwing™ QCS6490 and…

4 days ago

The long march towards delivering CRA compliance

Time is running out to be in full compliance with the EU Cyber Resilience Act,…

4 days ago

Extra Factor Authentication: how to create zero trust IAM with third-party IdPs

Identity management is vitally important in cybersecurity. Every time someone tries to access your networks,…

5 days ago