How to format a USB stick (flash drive) with FAT32 for use on Linux and Windows?

63,209

Windows will often use external media, such as USB flash drives, in an unpartitioned way -- that is, there's no partition table and the filesystem is written to the whole disk. If your disk is set up in this way, you should use /dev/sdf directly, as in:

mount /dev/sdf /mnt

You could use mkfs, fsck, and other tools in a similar way. You can use blkid to verify this, as in blkid /dev/sdf. If it tells you that /dev/sdf is a FAT (or some other) filesystem, then my hypothesis is correct.

If the disk has no data you want to preserve and you want to create a fresh filesystem on it, you can either do so on the whole disk or you can use fdisk, parted, or some other tool to create a fresh (empty) partition table. In fdisk, you'd do this with the o command at the main menu. This will wipe the existing "partitions" (which are probably just fdisk's desperate attempt to interpret the first sector of a FAT filesystem) and create a new empty partition table. You'd then use n to create a new partition, save the changes with w, and use mkfs or mkdosfs outside of fdisk to create a fresh filesystem on /dev/sdf1.

Note that Windows only recognizes the first partition on a USB flash drive that contains a partition table. Thus, if you want more than one partition, be sure that the first one is the one that will be accessible from Windows.

Share:
63,209

Related videos on Youtube

jah
Author by

jah

Updated on September 18, 2022

Comments

  • jah
    jah over 1 year

    I want to format a memory stick for moving data between Windows 7 and a non-networked Ubuntu server (Precise).

    I'm not sure that either of the two ways I've tried are correct, even though I can read from and write to the drive on both machines.

    I get a very weird looking partition listing from fdisk if I format the drive on Windows (using the Disk Management tool), but it seems to be OK in terms of reading and writing on Linux and Windows.

    image showing the output of fdisk for a windows formatted drive

    and cfdisk reports

    FATAL ERROR: Bad primary partition 1: Partition begins after end-of-disk.
    

    If, as some advocate, I use cfdisk to create a full-disk primary partition of type b (or fdisk to create a partition that starts at block two-thousand and something) and then issue

    sudo mkfs.vfat -n some_label /dev/sdf1
    

    then Windows won't recognise the file system (after aeons of thinking about it).

    Linux and Windows will happily read and write a 2GB dive if I make that same partition, but then issue:

    sudo mkfs.vfat -I -n some_label /dev/sdf
    

    but this makes that full-disk partition show as free-space in cfdisk and fdisk and Windows doesn't like the 16GB drive.

    I've tried using parted too, but Windows is never happy with any partitions I create on Linux.

    I'm concerned that, whilst the drive seems to work, I may discover that the data isn't being transferred faithfully.

    I'm using SanDisk Cruzer drives of various ages, flavours and sizes.

    Is the correct way to format on windows and ignore the problems that cfdisk and fdisk have or is there another correct way in which everyone is happy with the drive?

    • GENiEBEN
      GENiEBEN over 10 years
      Have you tried using "HP USB Format" tool instead of diskmgmt.msc?
    • 72DFBF5B A0DF5BE9
      72DFBF5B A0DF5BE9 over 10 years
      use gparted, create NTFS disk, use it in windows. Another way is simply delete everything from it (no partition at all), then partition it in windows with compmgmt.msc or HP USB Tool, then use it in Windows and linux.
    • jah
      jah over 10 years
      @GENiEBEN I haven't and I don't seem to be able to find a reputable source for it either.
  • jah
    jah over 10 years
    That mess reported by fdisk (see the screenshot in the question) can be corrected by zeroing the drive with dd if=/dev/zero of=/dev/sdf or shred -n 0 -z /dev/sdf before creating a partition.
  • jah
    jah over 10 years
    Create a partition with fdisk /dev/sdf (using the defaults presented in interactive mode) of type b (Windows95) (make it type c (Windows95 (LBA)) for a 16GB drive - this is what Windows does) and format it using either mkfs.vfat /dev/sdf1 or in Windows with the Disk Management tool (which reports the file system as 'RAW' when the drive is first plugged-in). Both ways will result in a drive which fdisk reports consistently. Note that this results in a partition which is not 'whole disk' and so /dev/sdf1 is the one to mount.
  • jah
    jah over 10 years
    I couldn't confirm your hypothesis @Rod Smith because this drive is not now 'whole disk': sudo blkid /dev/sdf reports nothing at all, but sudo blkid /dev/sdf1 does report TYPE="vfat". Thank you very much for your answer, I now have working drives I have confidence in.