Formatting a storage device for use with all Operating systems

Motivation

Sometimes out-of-the-box storage device (USB stick, memory card, external hard drive) comes with a formatting that only satisfies on operating systems, and the stick cannot be mounted using other operating systems.

Similar problems can occur after formatting a storage device with recent Windows versions (uses NTFS) or MacOS (whatever) or after dd-ing an ISO image on it in Linux (block size confusion).

The following command line snippets for Linux should make any storage device usuable with all operating systems and most or all devices (like smartphones, digital cameras, media players, ...).

Disclaimer 1: Use at Your own risk

In case of certain problems (i.e. if the storage device is not detected at all) the following snippets can destroy all data even on your internal storage device (i.e. main hard disc resp. SSD).

So USE AT YOUR OWN RISK.

Disclaimer 2: 2 TB warning

If the storage devices provides more than 2 TB of storage better use gparted or the like after clearing the exisiting paritition table with dd.

Solution

For easier reading the following text will use "storage device" to refer to "USB memory stick or memory card".

Making sure the storage device is detected and remember device partition

To make sure the storage device is detected we list the permanent partitions, connect the storage device, wait a bit, and list the partitions again:

cat /proc/partitions


# connect device
# wait
# evtl. observer dmesg or syslog


cat /proc/partitions

Only if the latter partition list shows a partition the former partition list did not can we assume the device is detected.

Usually but not always the new parititon entry or entries appear at the bottom of the list.

On legacy linuxes it should be the "highest" sd[a-z] value, i.e. sdb, sdc, ...

We are only interested in the device level partition, like sdb. Eventually detected actual paritions like sdb1, sdb2, ... can be ignored.

# assuming the memory devices showed up as sdc & sdc1
SDDEV=/dev/sdc

Clean eventual partition table

To get rid of any partition table Zero the first few blocks. 4096  0s should be satisfactory for devices over 2 TB too.

dd if=/dev/zero of=${SDDEV} bs=4096 count=1

Create and format partition with gparted

I recommend to use the X11 tool gparted for the remaining steps:

  • if you don't have gparted installed yet install it now
  • LC_ALL="C" gparted &
  • let it scan your devices (may take a bit)
  • At the right select the storage device to operate on (see above)
  • In the menu select "Device", "Create partition table", type msdos should be find, "Apply"
  • Select the "unallocated" line in the partition list
  • In the menu select "Partition", "New"
  • Change file system to fat32 (or NTFS for full large file support, locking out anything but Windows and Linux)
  • Optionally enter a lable
  • In the menu select "Edit", "Apply all operations"
  • Wait a bit
  • Close the success dialog, review the partition list
  • End gparted