How to Format USB Drives in Linux (2024)

Introduction

Formatting a USB drive prepares it for different file systems and ensures compatibility across various platforms. In Linux, formatting a USB requires knowledge of the commands and tools for managing storage devices.

In this tutorial, you will learn how to format a USB drive in Linux using three methods.

How to Format USB Drives in Linux (1)

Prerequisites

  • A system running Linux.
  • A USB drive.
  • Access to the terminal (Ctrl + Alt + T).
  • A user account with root privileges.

Which File System to Use for USB Formatting?

The file systems you can use for formatting a USB drive differ by maximum file size and operating system compatibility. The most commonly used file systems when formatting a USB drive are:

  • FAT32.
  • NTFS.
  • exFAT.
  • UDF.

Their main features and differences are in the following table:

File SystemSupported File SizeCompatibilityIdeal Usage
FAT32up to 4 GBWindows, macOS, and Linux.For maximum compatibility.
NTFS16 EiB - 1 KBWindows, macOS (read-only), and most Linux distributions.For internal drives, Windows system files, and large files.
exFAT16 EiB - 1 KBWindows, macOS, and Linux (requires extra drivers to access).For files larger than 4 GB.
UDF16EiB - 1KBWindows, macOS, and Linux.For maximum compatibility when transferring large files.

Important: Formatting a USB drive erases all data stored on it. Toprevent data loss, always back up your data before formatting. Although some data may be recovered from a formatted USB stick, it depends on the formatting method used, the extent of data overwriting during formatting, and the effectiveness of data recovery tools.

If the stick contains sensitive information you want to erase, employ additional measures such as secure deletion ordisk encryption.

How to Format a USB Drive in Linux

The following tools can be used to format a USB drive in Linux:

  • The terminal
  • Disk Utility
  • GParted

The sections below outline the steps for each tool.

Method 1: Format USB Using the Terminal

The terminal is the easiest and fastest way to format a USB drive in Linux. The procedure consists of three steps:

1. Locating the USB drive.

2. Unmounting and formatting the USB drive.

3. Verifying the process was successful.

Follow the instructions below to format a USB drive using the terminal.

Step 1: Locate USB Drive

Open the terminal and run the following command:

df

The terminal prints out a list of all mounted partitions and relevant information: used space, available space, used space percentage, and the path.

Locate the USB in the list and find the corresponding device. In this example, the USB drive is /dev/sdb1:

How to Format USB Drives in Linux (2)

Note: If you are unsure of the drive designation, unplug the USB drive temporarily before running the df command again. The device that is now gone from the list is your USB device. You can also spot it by inspecting the total drive capacity.

Step 2: Unmount and Format USB Drive

Unmount the USB drives before formatting. To do so, use the following command:

sudo umount /dev/[device_name]

Replace [device_name] with the USB device name found in the previous step. For example:

How to Format USB Drives in Linux (3)

After unmounting, format the USB drive by running a command or using a Bash script.

Format Using a Command

Use one of the commands below to format the USB drive. Depending on your preferred file system, choose one of the following:

  • FAT32:
sudo mkfs.vfat /dev/[device_name]
  • NTFS:
sudo mkfs.ntfs /dev/[device_name]
  • exFAT:
sudo mkfs.exfat /dev/[device_name]

Format Using a Bash Script

Createa Bash scriptto simplify formatting USB drives that require frequent formatting.Using a script is simpler than memorizing Linux commands - just run the script to format the drive. Note that the following script works only with UDF.

Follow the steps below:

1. Run the command below to install the prerequisite packages for running the script:

sudo apt install udftools coreutils vim-common

2. Using a web browser, navigate to the script GitHub page and download the Bash script.

3. Make the script executable using chmod:

chmod +x format-udf.sh

4. Run df to find your USB device name. Use the syntax below to format the device:

./format-udf.sh /dev/[device_name]

For example:

How to Format USB Drives in Linux (4)

Step 3: Verify USB Drive Formatting

Confirm the formatting process has been completed successfully with the following command:

sudo fsck /dev/[device_name]
How to Format USB Drives in Linux (5)

A USB drive with no files indicates successful formatting:

Method 2: Format USB Using Disk Utility

The GNOME Disk Utility is a GUI tool for partitioning and formatting storage drives in Linux. Follow the steps below to format a USB drive using the Disk Utility tool.

Step 1: Open Disk Utility

To open the Disk Utility:

1. Launch the Application menu.

2. Type "disk" in the search bar.

3. Click the Disks icon.

How to Format USB Drives in Linux (6)

Step 2: Identify the USB Drive

Locate the USB drive from the left panel and select it. The right panel contains drive details, such as the model name, size, serial number, and contents.

How to Format USB Drives in Linux (7)

Step 3: Format the USB Drive

1. Click the gear icon and select the Format Partition option from the drop-down menu.

How to Format USB Drives in Linux (8)

2. Type the preferred name for the USB drive. Optionally, enable the Erase option to overwrite the existing data from the USB drive. Choose the file system type and click on the Next button.

How to Format USB Drives in Linux (9)

3. A pop-up appears with a warning message about data deletion and formatting details. Click the Format button to start the formatting process.

How to Format USB Drives in Linux (10)

4. The progress line shows the remaining time until the formatting is completed. When the job is complete, close Disk Utility.

Method 3: Format USB Using GParted Tool

Formatting via GParted takes the most time as it involves an additional step – installing the tool. However, it is a handy tool you can use even after formatting the USB drive.

Follow the steps below to format a USB drive using the GParted tool.

Step 1: Install GParted Tool

1. Open the terminal and install the GParted tool:

sudo apt install gparted -y 
How to Format USB Drives in Linux (12)

Wait until the process is complete.

2. Run GParted with:

sudo gparted

The terminal opens the GParted program.

How to Format USB Drives in Linux (13)

Step 2: Select the USB Device and File System

1. Select your device from the drop-down menu at the top of the GParted home screen.

How to Format USB Drives in Linux (14)

2. Right-click the partition and select Format to. Choose the preferred file system from the list to continue.

How to Format USB Drives in Linux (15)

Step 3: Start the Process

1. Click the green checkmark button to apply all operations.

How to Format USB Drives in Linux (16)

2. A pop-up appears with a warning message about data deletion. Click Apply to continue.

How to Format USB Drives in Linux (17)

The GParted program formats the drive. The time required for the formatting process varies depending on the size and type of the USB drive.

3. Click the Close button to exit the menu when the operation completes.

How to Format USB Drives in Linux (18)

How to Wipe USB on Linux

When you format a device, the system creates a new partition, but the original data can remain on the device until it is overwritten with new data. Some advanced recovery tools make data retrieval from formatted devices possible, which can be a severe problem when working with sensitive data.

This section shows how to completely wipe a USB stick and prevent any data from being recovered. Follow the steps below:

1. Locate the device by running the command below:

df
How to Format USB Drives in Linux (19)

Locate your device in the output based on its name or storage size.

2. Unmount the device using the syntax below:

sudo umount /dev/[device]

Replace [device] with your device name.

3. Use the dd command to overwrite the USB drive with zeroes. The syntax is:

sudo dd if=/dev/zero of=/dev/[device] bs=4096 status=progress

For example:

How to Format USB Drives in Linux (20)

Important: Make sure to specify the correct device name. If you provide a wrong device name, you risk destroying data on other partitions, such as the hard drive.

The command overwrites the USB drive with zeroes. A zero overwrite is usually sufficient. However, if you want to ensure no data is recoverable from the device, overwrite the drive with random data instead of zeroes. The syntax is:

sudo dd if=/dev/urandom of=/dev/[device] bs=4096 status=progress

Note: Another way to destroy data on a device is to use the shred command.

How to Recover Data From Formatted USB

If you formatted your USB drive and lost important data, you can attempt to recover it. Different data recovery tools can rescue data if it has not been overwritten. This section lists two methods for recovering deleted data.

Recover Data Using photorec

photorec is part of the testdisk utility, an open-source CLI data recovery tool that helps users recover data from lost or deleted Linux partitions. It can also be used to recover non-bootable partitions caused by deleting partition tables or by a cyber attack. Follow the steps below to recover files using photorec:

1. Update the system package repository information to ensure you install the latest testdisk version. Run:

sudo apt update

2. Install testdisk by running the command below:

sudo apt install testdisk

3. After completing the installation, start the photorec utility as an administrator by running the following in the terminal:

sudo photorec
How to Format USB Drives in Linux (21)

The tool starts in interactive mode, first prompting you to select the disk drive you want to scan for lost data. Use the up and down arrow keys to select the disk and the right arrow key to move the highlight to Proceed. Press Enter to confirm your selection.

4. Use the arrow keys to select the partition on the disk you want to scan or select the whole disk, and press Enter to confirm:

How to Format USB Drives in Linux (22)

5. Select the filesystem type on the drive on the next screen. Make sure to select the appropriate one so that photorec knows which recovery method to use:

How to Format USB Drives in Linux (23)

6. Use the arrow keys to select the destination in which to save the recovered files:

How to Format USB Drives in Linux (24)

Confirm the directory with c and the app scans the drive for deleted files. When the process completes, the recovered files are saved in the directory you selected in the previous step:

How to Format USB Drives in Linux (25)

Restore Data Using foremost

foremost is an open-source tool that allows users to recover deleted files from a hard drive, memory card, USB, and other types of memory devices. Follow the steps below to install foremost and recover deleted files from a USB:

1. Update your package repository information:

sudo apt update

2. Install foremost by running the following command:

sudo apt install foremost

3. Insert your USB stick and run the df command to find and copy the device path:

df

4. After copying the device path, use the syntax below to scan the device for deleted files:

sudo foremost -i [device_path]

Replace [device_path] with the path to your USB device you noted in the previous step. By default, foremost creates a directory named output inside the directory it was launched from and uses it as the target destination for recovered files.

Within that directory, foremost creates a subdirectory for each supported file type it retrieves from the drive. If you want to save the files to a different location, specify the -o flag, followed by the destination path.

If you want to retrieve only specific file types, use the -t flag followed by the file type. For example, to recover only .jpg files, enable verbose mode (-v) to see the process details and save the files to a custom output. Use a command like the one below:

sudo foremost -t jpg -v -i /dev/sdc -o /home/bosko/recovered_files
How to Format USB Drives in Linux (26)

Conclusion

This article showed how to format a USB drive in Linux using several methods, and different ways to wipe a USB clean or retrieve deleted data from a USB device. Whatever your case, follow the steps outlined in this tutorialto simplify USB management.

Next, see how to mount a Linux partition or learn about swap partitions.

How to Format USB Drives in Linux (2024)

FAQs

How can I Format a USB drive in Linux? ›

Follow the steps below to format a USB drive using the Disk Utility tool.
  1. Step 1: Open Disk Utility. To open the Disk Utility: ...
  2. Step 2: Identify the USB Drive. Locate the USB drive from the left panel and select it. ...
  3. Step 3: Format the USB Drive.
Apr 30, 2024

How to Format a drive on Linux? ›

How to Format a Hard Drive in Linux
  1. Step 1: Select a Drive to Format. First, choose a disk that you want to format. ...
  2. Step 2: Create a New Linux Partition for Disk. Now, we will create the partition on the device path “/dev/sda.” ...
  3. Step 3: Format Disk with Ext4. ...
  4. Step 4: Mount Partition.

How to completely reformat a USB drive? ›

To format a USB storage drive in Windows, connect it via a USB port and follow these steps:
  1. Open your File Explorer. ...
  2. From the menu, select "Format."
  3. Leave the settings at their defaults or select specific values as needed. ...
  4. Click "Start." A confirmation message will appear when formatting is complete.

How to Format FAT32 Linux command line? ›

In order to format a partition with an FAT32 filesystem, you need to use the “mkfs” command and specify the FAT32 filesystem. Again, run “lsblk” with the “-f” option to make sure that your changes were written to the disk. You can mount your newly created partition by using the “mount” command.

How to reset USB on Linux? ›

Method #1: Ask the Linux kernel to reset the device
  1. Without any arguments, usbreset responds with a list of USB devices. ...
  2. You must be root to actually reset a device (hence sudo).
  3. The device can be chosen by its bus address (bus number and device number). ...
  4. The device can also be chosen by its Vendor / Product IDs.

What is the Linux disk format tool? ›

  • fdisk Command. fdisk is a versatile and widely used command-line tool that facilitates the creation and manipulation of disk partition tables, with support for various partition table formats, including MS-DOS and GPT. ...
  • GNU Parted. ...
  • Gparted. ...
  • GNOME Disks a.k.a ( GNOME Disks Utility) ...
  • KDE Partition Manager. ...
  • Qtparted.
Oct 10, 2023

How to format a drive in terminal? ›

Here is how to format a hard drive using Terminal:
  1. Enter “diskutil list” to see all available drives and their partitions.
  2. Identify the drive you want to format.
  3. Enter “diskutil unmountDisk /dev /diskX” to unmount the drive. ...
  4. Enter “diskutil eraseDisk APFS MyDrive /dev/diskX” to format the drive.
Nov 16, 2023

How to format NTFS USB on Linux? ›

Using the Terminal:
  1. Open a terminal window.
  2. Identify the USB drive's device name using the lsblk or fdisk -l command.
  3. Unmount the USB drive if it is currently mounted.
  4. Format the USB drive using a specific command for the desired file system (e.g., mkfs. fat for FAT32, mkfs. ntfs for NTFS, mkfs. ext4 for ext4).
May 23, 2024

What is the WipeFS command in Linux? ›

wipefs can erase filesystem, raid or partition-table signatures (magic strings) from the specified device to make the signatures invisible for libblkid. wipefs does not erase the filesystem itself nor any other data from the device.

How do you force Format a USB drive? ›

Formatting Drives in Windows
  1. Insert a USB drive into a USB port.
  2. Open File Explorer.
  3. Click on This PC from the left pane.
  4. Under the "Devices and drives" section, right-click the flash drive and select the Format option.
  5. Use the "File system" drop-down menu and select the preferred option.

How do I erase all data on my USB drive? ›

Delete all files on a flash drive via formatting to get free space
  1. Press Windows + R simultaneously, input “diskmgmt. ...
  2. Locate the partition on a USB flash drive, right-click it and choose Format.
  3. In the pop-up small window, choose a proper file system for the partition and click OK.

Why can't I Format a USB drive? ›

The USB drive may get corrupted or damaged and caused the computer can't format USB. The common reasons caused the error can be that the USB drive got virus-infected, USB bad sectors, physical damage, and the file system crashed.

How to format the disk in Linux? ›

Linux Format Disk ext4 File System
  1. Use the command sudo mkfs -t ext4 /dev/sdb to format your disk partition.
  2. Once done with it, you must verify the file system change. ...
  3. Once complete, the terminal will list blocked devices. ...
  4. Confirm the formatting of the preferred partition.
Jan 11, 2024

How to format a USB drive in Ubuntu? ›

Quick Steps
  1. Open the Disks tool.
  2. Select one or more volumes on your USB drive.
  3. Click the gear icon and select Format.
  4. Select a Quick format and choose a file system.
  5. Click Format to erase and reformat the drive.

What is format command in Linux? ›

The general syntax for formatting a disk partition in Linux is: mkfs.< filesystem> </path/to/disk/partition> For example, to format our newly created /dev/sda2 partition, we can use this command: mkfs.ext4 /dev/sda2.

How to format a write protected USB on Linux? ›

Solution 1: Format USB Drive via Terminal (Command Prompt)
  1. Step 1: Launch Terminal on your Linux system.
  2. Step 2: Identify the attached USB drive.
  3. Step 3: Unmount the disk.
  4. Step 4: Format the USB drive.
  5. Step 1: Connect the USB drive and select it.
  6. Step 2: Wait for the scan to be over.
  7. Step 3: Restore your data.

Is FAT32 compatible with Linux? ›

All of the Linux filesystem drivers support all three FAT types, namely FAT12, FAT16 and FAT32.

How to create a FAT32 partition in Linux? ›

Create the DOS partition table
  1. n => New partition —accept all defaults for partition type, partition number, first sector and last sector, so it takes all the space available on the device.
  2. t => Changes a partition type.
  3. b => Picks W95 FAT32.
  4. p => Shows partition info.
  5. w => Writes changes and exit.

Top Articles
Acura RDX vs MDX: What's the Difference?
Customer Support Ruling | Postal Explorer
Compare Foods Wilson Nc
Genesis Parsippany
Myexperience Login Northwell
<i>1883</i>'s Isabel May Opens Up About the <i>Yellowstone</i> Prequel
Clafi Arab
Goteach11
Autozone Locations Near Me
Baseball-Reference Com
Premier Boating Center Conroe
Phillies Espn Schedule
Simple Steamed Purple Sweet Potatoes
Morocco Forum Tripadvisor
Simplify: r^4+r^3-7r^2-r+6=0 Tiger Algebra Solver
Beebe Portal Athena
Skyward Login Jennings County
The Exorcist: Believer (2023) Showtimes
Union Ironworkers Job Hotline
Where to Find Scavs in Customs in Escape from Tarkov
Scotchlas Funeral Home Obituaries
Amortization Calculator
Dwc Qme Database
Shiftselect Carolinas
Woodmont Place At Palmer Resident Portal
Naval Academy Baseball Roster
Craigslist Pennsylvania Poconos
Apartments / Housing For Rent near Lake Placid, FL - craigslist
Everything To Know About N Scale Model Trains - My Hobby Models
Inter Miami Vs Fc Dallas Total Sportek
Bra Size Calculator & Conversion Chart: Measure Bust & Convert Sizes
Craigslist Comes Clean: No More 'Adult Services,' Ever
Proto Ultima Exoplating
Earthy Fuel Crossword
Blush Bootcamp Olathe
47 Orchid Varieties: Different Types of Orchids (With Pictures)
Viewfinder Mangabuddy
Mcgiftcardmall.con
One Main Branch Locator
Tillman Funeral Home Tallahassee
Pay Entergy Bill
Craigslist - Pets for Sale or Adoption in Hawley, PA
Lonely Wife Dating Club בקורות וחוות דעת משתמשים 2021
All Obituaries | Sneath Strilchuk Funeral Services | Funeral Home Roblin Dauphin Ste Rose McCreary MB
The Attleboro Sun Chronicle Obituaries
VDJdb in 2019: database extension, new analysis infrastructure and a T-cell receptor motif compendium
bot .com Project by super soph
The Largest Banks - ​​How to Transfer Money With Only Card Number and CVV (2024)
Aaca Not Mine
Tanger Outlets Sevierville Directory Map
Latest Posts
Article information

Author: Kareem Mueller DO

Last Updated:

Views: 6002

Rating: 4.6 / 5 (46 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Kareem Mueller DO

Birthday: 1997-01-04

Address: Apt. 156 12935 Runolfsdottir Mission, Greenfort, MN 74384-6749

Phone: +16704982844747

Job: Corporate Administration Planner

Hobby: Mountain biking, Jewelry making, Stone skipping, Lacemaking, Knife making, Scrapbooking, Letterboxing

Introduction: My name is Kareem Mueller DO, I am a vivacious, super, thoughtful, excited, handsome, beautiful, combative person who loves writing and wants to share my knowledge and understanding with you.