How to Format a USB Drive on Linux
Table of Contents
USB drives are widely used for storing and transferring data between different devices. However, sometimes you may need to format a USB drive to change its file system or to erase its contents. If you’re using Linux, formatting a USB drive can be done easily through the command line. In this step-by-step guide, we’ll show you how to format a USB drive on Linux using the fdisk utility and the mkfs.vfat command.
Using mkfs.vfat
mkfs.vfat is a command-line utility used on Linux and other Unix-like operating systems to create a File Allocation Table (FAT) file system on a block device, typically a partition or a removable storage device such as a USB drive or SD card. FAT is a file system commonly used in Windows and other operating systems, and it is supported by many devices that use removable storage.
The “mkfs” part of the command stands for “make filesystem,” while the “.vfat” extension specifies that the utility should create a FAT file system. The syntax of the mkfs.vfat command typically includes the device name of the block device to be formatted and any additional options or parameters.
Step 1: Connect USB Drive
Connect the USB drive to your Linux computer’s USB port.
Step 2: Open Terminal
Open the terminal by pressing Ctrl + Alt + T on your keyboard or by searching for it in the applications menu.
Step 3: Get Device Name
To list all the available storage devices on your system, run:
lsblk
Note down the device name of your USB drive (e.g. /dev/sdb).
Step 4: Unmount USB Drive
To unmount the USB drive so that you can format it, run:
umount /dev/sdb
Step 5: Launch fdisk
To launch the fdisk utility, which you can use to create a new partition on your USB drive, run:
sudo fdisk /dev/sdb
Step 6: Display Partition Table
Type the letter p and press Enter to display the current partition table of your USB drive.
Step 7: Delete Existing Partitions
Type the letter d and press Enter to delete any existing partitions on your USB drive. If there are multiple partitions, you may need to repeat this step until all partitions are deleted.
Step 8: Create New Partition
Type the letter n and press Enter to create a new partition on your USB drive.
Step 9: Choose Partition Type
Choose the partition type by typing the letter p for primary partition, e for extended partition, or l for logical partition and press Enter.
Step 10: Assign Partition Number
Type 1 to assign the partition number and press Enter.
Step 11: Select Starting Sector
Press Enter to accept the default starting sector.
Step 12: Set Partition Size
Type +4G to set the partition size to 4 gigabytes (adjust this value according to your needs) and press Enter.
Step 13: Write Changes
Type the letter w and press Enter to write the changes to the partition table and exit fdisk.
Step 14: Format New Partition
sudo mkfs.vfat -F 32 /dev/sdb1
This will format the new partition on your USB drive as a FAT32 file system.
Step 15: Remove USB Drive
Once the formatting process is complete, run:
sudo eject /dev/sdb
This will safely remove your USB drive from your computer.
Conclusion
Formatting a USB drive on Linux is a straightforward process that can be done through the command line. By following the steps outlined in this guide, you can easily format your USB drive and prepare it for storing or transferring your data. Always remember to back up any important data before formatting your USB drive, as formatting will erase all data on the drive. With a formatted USB drive, you’ll be ready to store and transfer your files with ease.