Partition and Format a USB Flash Drive with Linux

From Free Knowledge Base- The DUCK Project: information for everyone
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 (pendrive pen drive flash stick) 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. Also read USB Flash Drive Formats for more information on partition and format options for this type of flash memory.

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 block device node 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
  • exFAT ***
sudo mkfs.exfat /dev/sdc1
  • remember to replace "sdc" with the assignment of your usb flash drive, which might be something else like sdb sdd etc...
  • *** note on exFAT: requires exfat-utils (sudo apt install exfat-utils) read exFAT on Linux for details. Both exFAT and NTFS are Microsoft proprietary file systems.

Using this method and applying a FAT32 file system is verified to allow you to read and write to the flash drive under Linux and Windows 7. There is a file size limitation with FAT32. You cannot transfer a file that is greater than 4GB in size to a FAT32 file system. Files larger than 4GB can NOT be stored on a FAT32 volume. Formatting the flash drive as exFAT or NTFS will resolve this issue.

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...

Format USB Drive via USB Stick Formatter

mintstick - A utility included with the Mint Linux distribution that allows for the quick format of a USB flash drive from an easy to use graphical interface within the cinnamon desktop. There is also USB Image Writer as well as USB Stick Formatter. It is located in the MENU under:

  • Menu -> Accessories -> USB Stick Formatter
$ /bin/sh /usr/bin/mintstick 
Usage: mintstick [--debug] -m [format|iso]              : mode (format usb stick or burn iso image)
       mintstick [--debug] -m iso [-i|--iso] iso_path
       mintstick [--debug] -m format [-u|--usb] usb_device 
                          [-f|--filesystem] filesystem

Linux Mint Package Install - https://community.linuxmint.com/software/view/mintstick

This utility is very easy to operate and works well. You will be prompted for elevated privileges to perform actual format.

Writing an ISO Image to USB Stick

There are a number of Bootable USB flash drive utilities that you can use for this purpose, even if it is not necessary to have a bootable image. Some things to keep in mind include the tip, don't use USB Image Writer to burn a windows ISO image to flash media. For this purpose WoeUSB is recommended. Even the popular Etcher aka balenaEtecher is not recommended for creating bootable USB media from a Windows ISO image.