Partition and Format a USB Flash Drive with Linux

From Free Knowledge Base- The DUCK Project: information for everyone
Revision as of 13:24, 13 November 2019 by Ke0etz (Talk | contribs)

Jump to: navigation, search

This page is part of Linux and Your USB Flash Drive and applies to Solid State Removable Storage. Although the new USB Flash Drive that you just took out of the bubble pack is already formatted and ready to use, I would suggest you delete the existing partition, and start over. This is a good idea to protect you from getting a virus. In the past users have had to cope with companies like Sandisk and their U3 Flash Drive Virus. They really did intentionally install a virus on all of the flash drives they sold people! Other times rogue employees have been behind factory new flash media having a virus pre-installed. If you partition and format your flash drive before use then you know what's on it.

You can read about Recommend File System for Linux Use on your USB Flash Drive for some background. NTFS or FAT32 is recommended due to its compatibility with Windows however if you only plan to use the flash drive on linux systems then you can also use EXT4.

You will have to insert the flash drive then make sure it is not mounted, if your system uses automount then you will have to manually unmount the flash drive first.

Partition and Format USB Drive via Terminal

If your flash drive already has a partition table and you simply wish to reformat the drive then skip to step #3. In our example we will partition and format a 128GB flash drive attached at sdc.

1. Determine the assignment of your flash drive

fdisk -l|grep sd..

In the absence of having a partition on the flash drive you will observe only the device assignment:

Disk /dev/sdc: 119.6 GiB, 128446365696 bytes, 250871808 sectors

2. Partition the flash drive

echo 'start=2048, type=83' | sudo sfdisk /dev/sdc
  • remember to replace "sdc" with the assignment of your usb flash drive, which might be something else like sdb sdd etc...

3. Format the flash drive
If you created only a single partition on the flash drive (recommended) then you can assume that will be partition #1 or in our example sdc1

Format the flash drive with the file system type you prefer

  • FAT32
sudo mkfs.vfat /dev/sdc1
  • NTFS
sudo mkfs.ntfs /dev/sdc1
  • EXT4
sudo mkfs.ext4 /dev/sdc1
  • remember to replace "sdc" with the assignment of your usb flash drive, which might be something else like sdb sdd etc...

Format USB Drive via GParted GUI

If you're a graphical user interface sorta fella then this is an easy way to get the job done.

  1. GParted -> Device -> Create Partition Table -> Select new partition table type "msdos" - use this even if you plan to make an EXT4 partition and format EXT4
  2. GParted -> Partition -> New
  3. Choose Partition type xxxx
  4. GParted -> Partition -> Format to...