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

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.

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.

About the author

Denis Kariuki

Denis is a Computer Scientist with a passion for Networking and Cyber Security. I love the terminal, and using Linux is a hobby. I am passionate about sharing tips and ideas about Linux and computing.