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:
lsblkThis 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/sdb1Step 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.
- To format to FAT32 (Universal compatibility for Windows, Mac, and Linux):
sudo mkfs.vfat -F 32 /dev/sdb1- To format to NTFS (Best for large files used primarily with Windows):
sudo mkfs.ntfs /dev/sdb1- To format to ext4 (Standard native Linux filesystem):
sudo mkfs.ext4 /dev/sdb1Optional: 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.
- For FAT32, use the
-nflag:
sudo mkfs.vfat -F 32 -n MyStorage /dev/sdb1- For ext4 or NTFS, use the
-Lflag:
sudo mkfs.ext4 -L LinuxDrive /dev/sdb1Once 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.