How to format a usb on the ubuntu terminal

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.

See also  How to Install Dota 2 on Ubuntu

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.

How to format a usb on the ubuntu terminal 1

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

$ lsblk | grep media

How to format a usb on the ubuntu terminal 2

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

How to format a usb on the ubuntu terminal 3

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.

How to format a usb on the ubuntu terminal 4

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

$ sudo fsck /dev/sdb1

How to format a usb on the ubuntu terminal 5

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.

See also  Operate popular open source on Kubernetes – Attend Operator Day at KubeCon EU 2024

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.


Discover more from Ubuntu-Server.com

Subscribe to get the latest posts sent to your email.

Comments

No comments yet. Why don’t you start the discussion?

    Leave a Reply