How to re-format a USB drive to FAT32 in Linux

Written by - 0 comments

Published on - last updated on November 20th 2020 - Listed in Linux Windows


Many USB drives come by default pre-formatted in either FAT32 (which can be read by, to my knowledge, all operating systems) or NTFS, which is of course the Windows file system. 

But what if the drive is formatted in another file system type, let's say ext3? You may plug it to a Windows machine and the drive will not be recognized - therefore you cannot re-format the drive from within the Windows machine to re-use it.

In this case you need to format the drive on your Linux machine with the following commands.

First install the package dosfstools, which contains the program to format a file system in msdos (fat):

$ sudo apt-get install dosfstools

Then delete existing partitions on the drive (/dev/sdd in my case) using the d command:

$ sudo fdisk /dev/sdd

Command (m for help): p
Disk /dev/sdd: 2004 MB, 2004877312 bytes
Disk identifier: 0x00090d91
   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         590     1955840   83  Linux

Command (m for help): d
Selected partition 1

Command (m for help): p
Disk /dev/sdd: 2004 MB, 2004877312 bytes
Disk identifier: 0x00090d91
   Device Boot      Start         End      Blocks   Id  System

Followed by creating a new partition (still in fdisk):

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-590, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-590, default 590):
Using default value 590

... followed by setting the partition type to FAT32 (see fdisk option l to list the available types):

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): b
Changed system type of partition 1 to b (W95 FAT32)

Save your changes to the drive:

Command (m for help): w
The partition table has been altered!

$ sudo fdisk -l /dev/sdd
Disk /dev/sdd: 2004 MB, 2004877312 bytes
Disk identifier: 0x00090d91
   Device Boot      Start         End      Blocks   Id  System
/dev/sdd1               1         590     1957599    b  W95 FAT32

Now format the new partition with FAT32 using mkfs.msdos:

$ sudo mkfs.msdos -F 32 /dev/sdd1
mkfs.msdos 3.0.9 (31 Jan 2010)

And done! Your Linux and your Windows machine (and macOS) can now read and write on this drive.


Add a comment

Show form to leave a comment

Comments (newest first)

No comments yet.

RSS feed

Blog Tags:

  AWS   Android   Ansible   Apache   Apple   Atlassian   BSD   Backup   Bash   Bluecoat   CMS   Chef   Cloud   Coding   Consul   Containers   CouchDB   DB   DNS   Database   Databases   Docker   ELK   Elasticsearch   Filebeat   FreeBSD   Galera   Git   GlusterFS   Grafana   Graphics   HAProxy   HTML   Hacks   Hardware   Icinga   Influx   Internet   Java   KVM   Kibana   Kodi   Kubernetes   LVM   LXC   Linux   Logstash   Mac   Macintosh   Mail   MariaDB   Minio   MongoDB   Monitoring   Multimedia   MySQL   NFS   Nagios   Network   Nginx   OSSEC   OTRS   Observability   Office   OpenSearch   PGSQL   PHP   Perl   Personal   PostgreSQL   Postgres   PowerDNS   Proxmox   Proxy   Python   Rancher   Rant   Redis   Roundcube   SSL   Samba   Seafile   Security   Shell   SmartOS   Solaris   Surveillance   Systemd   TLS   Tomcat   Ubuntu   Unix   VMWare   VMware   Varnish   Virtualization   Windows   Wireless   Wordpress   Wyse   ZFS   Zoneminder