Difference between revisions of "Partition and Format a USB Flash Drive with Linux"

From Free Knowledge Base- The DUCK Project: information for everyone
Jump to: navigation, search
m (Partition and Format USB Drive via Terminal)
m
Line 1: Line 1:
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.
+
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.
 
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.
Line 31: Line 31:
 
  sudo mkfs.exfat /dev/sdc1
 
  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...''
 
*''remember to replace "sdc" with the assignment of your usb flash drive, which might be something else like sdb sdd etc...''
*<nowiki>***</nowiki> note on exFAT: requires exfat-utils (sudo apt install exfat-utils) read [[exFAT on Linux]] for details.
+
*<nowiki>***</nowiki> 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.
 
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.

Revision as of 15:46, 13 November 2019

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.

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