How to Format USB Drives in Linux?


Introduction

USB drives are popular portable storage devices that have become an integral part of our daily computing lives. They are small, lightweight, and easy to use, allowing us to store and transfer large amounts of data from one computer to another.

With the increasing demand for data storage and transfer, USB drives have evolved significantly over the years with larger capacities and faster transfer speeds. In addition to being used for personal data storage and transfers, USB drives are also used for booting operating systems on different computers.

Understanding the File Systems Supported by Linux

In Linux, the file system is responsible for managing files, directories, and permissions. Understanding how file systems work in Linux is crucial to formatting a USB drive properly.

Explanation of File Systems

Every file system has its set of rules for organizing data and maintaining metadata such as file permissions, ownership, and timestamps.

Linux supports various types of file systems that differ in their design principles, features, performance characteristics and compatibility with other operating systems. Some examples include Ext4 (Extended 4), XFS (eXtended File System), Btrfs (B-tree File System), FAT32 (File Allocation Table 32-bit) and NTFS (New Technology File System).

Commonly Used File Systems in Linux

Ext4 is the default file system used by most modern Linux distributions due to its robustness, scalability and improved performance over its predecessors like Ext2 and Ext3.

XFS is another popular choice for large-scale storage environments due to its support for high-performance storage subsystems such as RAID arrays.

FAT32 is a commonly used file system because it can be read by almost all current operating systems including Windows and Mac OS X without additional software drivers being installed.

NTFS was introduced with Microsoft Windows NT Operating System family and is an advanced file system that packs features such as encryption, access controls, and journaling.

Comparison between FAT32, NTFS and EXT4

FAT32 is a better option if you plan to use your USB drive across multiple operating systems like Windows or Mac OS X. However it's worth noting that this file format has limited security features and lacks support for large files. On the other hand, EXT4 provides high performance, reliability and improved scalability compared to both FAT32 and NTFS.

NTFS is known for its advanced security features but lacks support on many operating systems including most Linux distributions.

Preparing the USB Drive for Formatting

Connecting the USB drive to the computer

Before formatting a USB drive, you need to connect it to your Linux computer. Insert the drive into an available USB port on your computer.

If your system does not automatically mount the drive, you may need to manually mount it using the command line interface (CLI).

Checking if the drive is mounted

To check if your USB drive is mounted on your system, you can use a command such as `df -h`. This command lists all currently mounted file systems on your system. If you see a line that shows your USB device, then it's currently mounted.

Unmounting the Drive

Before formatting a USB device in Linux, you need to make sure that it's unmounted from your system. Unmounting means detaching or ejecting of a storage device from a specific location in a file hierarchy.

In order to unmount an external hard disk or flash drive in Linux through CLI interface, open up terminal and enter: `umount /dev/sdX`.

Formatting a USB Drive Using Command Line Interface (CLI)

Command Line Interface or CLI is an effective way of performing tasks in Linux. It provides you with a text-based interface, allowing you to execute commands quickly and efficiently.

Formatting a USB drive using CLI involves opening the terminal, identifying the USB drive using fdisk command, and creating a new partition on the drive using mkfs command. Here is a step-by-step guide −

Opening Terminal

The first step of formatting your USB Drive through Command Line Interface is opening the terminal. To open the terminal, press 'Ctrl+Alt+T' or search for Terminal in your distribution's application menu.

Identifying the USB Drive Using fdisk Command

The next step is to identify your USB Drive which needs formatting. In the terminal, type ‘sudo fdisk –l’.

This will list all available disks connected to your system including your hard drives and usb disks. You can identify your usb disk from this list by looking at its size.

Creating a New Partition on the Drive Using mkfs Command

Once you have identified which disk represents your usb drive (most commonly /dev/sdb), it’s time to create a new partition on it using mkfs command. The syntax for this command looks like below −

sudo mkfs -t [file_system_type] /dev/[usb_drive_name]

For instance, if you want to format your pen drive into FAT32 file system then use −

sudo mkfs -t vfat /dev/sdb1

This will format sdb1 partition of /dev/sdb as FAT32 file system. Formatting a USB drive using CLI is a quick, efficient, and effective way to format your USB drive in Linux.

Formatting a USB Drive using Graphical User Interface (GUI)

For those who prefer a more user-friendly approach, the graphical user interface (GUI) offers an easier way to format USB drives in Linux.

Installing GParted application

GParted is an open source partition editor that can be used to manage disk partitions. It can be used to create, delete, resize, move and copy partitions without data loss.

To install GParted on your Linux operating system, you need to follow these steps −

  • Open Terminal

  • Type "sudo apt-get update" and press enter

  • Type "sudo apt-get install gparted" and press enter

  • Enter your administrator password if prompted and wait for the installation process to complete

Launching GParted application

To launch GParted after installation −

  • Click on the Applications or Activities menu on your desktop environment.

  • Type "GParted" in the search bar.

  • Select Gparted from the list of applications displayed by typing [enter].

  • You may be asked to enter your password before proceeding.

Selecting and formatting the USB drive

To format a USB drive using GParted −

  • In Gparted GUI interface: Select the device from drop down menu in right corner of window

  • right-click on the usb drive you want to format and select "format to" from the context menu.

  • Choose your desired file system format, such as FAT32 or NTFS.

  • Click on the Apply button and wait for GParted to format the USB drive. This may take a few moments depending on the size of the drive.

Once formatting is complete, remove your USB drive from your computer and reconnect it. It should appear in your File Explorer as a newly formatted disk ready for use.

Mounting The Formatted Drive

Steps for Mounting Your Formatted Drive in Linux

To mount your freshly formatted USB drive in Linux, follow these steps −

  • Open a terminal window.

  • Create a directory where you want to mount your device using `mkdir`.

For instance −

sudo mkdir /mnt/usbdrive
  • Type `sudo mount /dev/sdX /mnt/usbdrive` (replace X with your device identifier) to mount the drive in that folder.

sudo mount /dev/sda /mnt/usbdrive
  • You can now access your device by navigating to `/mnt/usbdrive` in any file manager on your Linux machine.

Conclusion

In this article, we have covered various aspects related to formatting USB drives in Linux. We have started by discussing what USB drives are and their importance in modern computing. Then, we delved into different file systems supported by Linux and compared them based on their features and limitations.

Updated on: 05-Jun-2023

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements