Introduction / Why This Is Needed
Formatting a USB drive (flash drive or external hard disk) in Linux is a standard operation for preparing a device for use, resolving access issues, or changing the file system. This guide will help you safely format your drive by choosing the appropriate method: through a graphical interface or the terminal. You will learn how to identify the device, select a file system, and verify the result.
Requirements / Preparation
- A connected USB device to your computer.
- Administrator privileges (sudo) for operations via the terminal.
- To work with exFAT or NTFS file systems, some distributions may require installing additional packages:
- exFAT:
sudo apt install exfatprogs(Ubuntu/Debian) orsudo dnf install exfat-utils(Fedora). - NTFS:
sudo apt install ntfs-3g(Ubuntu/Debian) orsudo dnf install ntfs-3g(Fedora).
- exFAT:
- A backup of important data from the flash drive — formatting will permanently delete all files.
Method 1: Graphical Interface (GNOME Disks)
This is the simplest and most intuitive method, suitable for beginners in distributions with the GNOME desktop environment (Ubuntu, Fedora, Debian with GNOME).
Step 1: Open the "Disks" Utility
Find the "Disks" program in your application menu (or run gnome-disks in the terminal).
Step 2: Select Your USB Device
In the left panel listing devices, locate your flash drive. Pay attention to the model and size — this will help you avoid confusing it with your system disk.
Step 3: Erase Existing Data and Create a New Partition Table
⚠️ Important: This step will delete all partitions and data on the selected device.
- Click the menu button (three dots or an arrow) in the top-right corner of the device panel.
- Select "Format Disk...".
- In the dialog window, choose a partition scheme:
- MBR — for compatibility with older systems (up to 2 TB).
- GPT — the modern standard, recommended for disks larger than 2 TB and UEFI systems.
- Click "Format..." and confirm the action.
Step 4: Format the Created Partition
After erasing, the disk will show unallocated space.
- Click the "+" (Create Partition) button in the "Unallocated Space" section.
- Specify the partition size (you can leave the default to use the entire disk).
- In the "File System Type" field, select the desired type:
- FAT (FAT32) — for maximum compatibility.
- exFAT — for large files (>4 GB) and cross-platform use.
- NTFS — for use with Windows.
- Give the partition a name (e.g.,
MYUSB). - Click "Create". Formatting will begin automatically.
Step 5: Verification
After completion, the partition will mount and appear in your file manager. You can open it to confirm it is empty.
Method 2: Terminal (Command Line)
This method provides more control and is suitable for servers or systems without a graphical interface.
Step 1: Identify the Device Path
💡 Tip: Do not confuse
/dev/sda(usually the system disk) and/dev/sdb(the second device, often a USB). A mistake will lead to data loss on your system disk!
Run the command:
lsblk
You will see a list of all block devices. Find your flash drive by its size (SIZE). The device path will look like /dev/sdX (disk) or /dev/sdXn (partition, e.g., /dev/sdb1).
Example output:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 238,5G 0 disk
├─sda1 8:1 0 512M 0 part /boot/efi
└─sda2 8:2 0 238G 0 part /
sdb 8:16 1 28,7G 0 disk
└─sdb1 8:17 1 28,7G 0 part /media/user/MYUSB <-- Our flash drive
In this example, the device is /dev/sdb, and the partition is /dev/sdb1.
Step 2: Unmount the Partition (if it is mounted)
If the lsblk output shows a mount point for your partition in the MOUNTPOINT column, you need to unmount it:
sudo umount /dev/sdXn
For example: sudo umount /dev/sdb1. If the partition is not mounted, the command will issue a warning — this is not an error.
Step 3: Perform the Formatting
Use the mkfs command (make filesystem). Syntax:
sudo mkfs -t <filesystem_type> /dev/sdXn
Examples for different file systems:
- FAT32 (4 GB file limit):
sudo mkfs -t vfat /dev/sdb1 - exFAT (recommended for modern needs):
sudo mkfs.exfat /dev/sdb1 - NTFS:
sudo mkfs.ntfs /dev/sdb1 - EXT4 (for Linux-only use):
sudo mkfs.ext4 /dev/sdb1
⚠️ Important: Replace
/dev/sdb1with the path to your partition. Specifying the disk without a partition number (e.g.,/dev/sdb) will erase all partitions on the device and create one new one.
Step 4: Verify the Result
- Check if the partition mounted automatically (it will appear in the file manager) or mount it manually:
sudo mount /dev/sdXn /mnt - Check the file system type:
In thelsblk -fFSTYPEcolumn for your partition, the selected type should be displayed (vfat,exfat,ntfs,ext4).
Verifying the Result
- Graphically: The device should appear in your file manager (Nautilus, Dolphin, etc.). Open it — the folder should be empty.
- Via terminal: Run
lsblk -fand confirm that your partition (/dev/sdXn) shows the correct file system (FSTYPE). - Try writing a file: Copy any small file to the flash drive and then delete it. This will confirm write functionality.
Possible Issues
- Error:
umount: /dev/sdXn: not mounted.- Cause: The partition is already unmounted.
- Solution: You can skip the unmount step and proceed to formatting.
- Error:
mkfs: failed to create file system on /dev/sdXn.- Cause 1: The device is busy (mounted elsewhere or in use by the system).
- Solution: Close all file managers and any windows showing files from the flash drive. Run
sudo umount -l /dev/sdXn(lazy unmount) and try again. - Cause 2: Insufficient permissions (did not use
sudo). - Solution: Add
sudoat the beginning of themkfscommand.
- Error:
mkfs.vfat: No space left on deviceorInvalid argument- Cause: The partition you are trying to format is too small or has an unusual size (e.g., it was used for LVM).
- Solution: Ensure you are specifying the correct path to the partition (e.g.,
/dev/sdb1), not the disk (/dev/sdb). If no partitions exist, create them first usingfdiskorparted.
- After formatting to exFAT/NTFS, the system does not mount the flash drive automatically.
- Cause: Your distribution may not have the package installed to support that file system.
- Solution: Install
exfatprogs(for exFAT) orntfs-3g(for NTFS), as indicated in the "Requirements" section. Reboot your computer or manually mount the partition:sudo mount -t exfat /dev/sdXn /mnt.
- The flash drive formatted, but only part of the capacity is visible.
- Cause: You formatted an old, small partition, and there is unused space on the device.
- Solution: Use
fdiskorpartedin the terminal or the "Disks" utility to delete the old partition and create a new one that occupies all available space.
Additional Tips
- Quick Format vs. Full Format: All described methods perform a quick format (only writing file system structures). For a full (slow) format that checks for bad blocks, use the
-coption withmkfs(e.g.,sudo mkfs.ext4 -c /dev/sdXn). This is useful for checking for bad sectors on an old flash drive. - Filename Encoding: For FAT32, the
cp866encoding is used by default (Cyrillic characters may not display correctly in Linux). When formatting viamkfs.vfat, you can specify the encoding:sudo mkfs.vfat -o iocharset=utf8 /dev/sdXn. - Labels (Volume Name): When formatting via the terminal, you can assign a volume label (name) immediately:
In the graphical "Disks" utility, this field is called "Volume Name".sudo mkfs.exfat -n MYUSB /dev/sdb1