Every now and then USB keys just seem to stop working. Most recently, I had a Verbatim key that somehow ended up with a single ~ 4 megabyte volume, formatted as FAT12.
The Disk Utility GUI in macOS was useless in addressing this. The 4 megabyte volume is the only one it would recognize. Running First Aid indicated everything was fine. Trying to re-partition the disk didn't work, without really indicating why, apparently because the 4 megabytes isn't enough space for anything but a FAT12 partition.
Anyways, it turns out the solution was pretty simple, which was to re-format at the disk level, and erase all the partitions. But, this has to be done from the command line, with the diskutil command. First I listed the available disks with diskutil list
/dev/disk4 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *31.0 GB disk4
1: Microsoft Basic Data 3.0 GB disk4s1
2: EFI ESP 4.3 MB disk4s2
(free space) 28.0 GB -
In this case the disk is /dev/disk4. The eraseDisk command worked without any hitches. Obviously it's incredible important to type the exact name of the disk, in this case /dev/disk4, otherwise you could be trying to erase your entire hard drive.
Note that namedoesnmatter is a placeholder for naming the disk, as indicated it doesn't matter and can really be any string.
diskutil eraseDisk free namedoesntmatter /dev/disk4
That's it! After running the eraseDisk command, the disk listed like so...
/dev/disk4 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *31.0 GB disk4
1: EFI EFI 209.7 MB disk4s1
(free space) 30.8 GB -
And showed up in Disk Utility! I was then able to use the Disk Utility GUI to reformat the disk to FAT32, using the Erase function. I haven't actually figured out how to use the diskutil command line utility to do the same thing, it seemed to fail at unmounting the disk, but I'm pretty sure I'm just getting the command wrong, and I'm happy to use the GUI if it actually works... Anyways, after formatting, the USB seems to work now!
/dev/disk4 (external, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *31.0 GB disk4
1: EFI EFI 209.7 MB disk4s1
2: Microsoft Basic Data UNTITLED 30.8 GB disk4s2
Annoying to have to go through this, but I'm happy this kind of path still exists.