How can I get the Volume Serial Number of a FAT volume? I need to programatically get the Volume Serial Number of a FAT volume (for example, a USB drive or removable SD card) in mac OS. Do you know of any program with which to do it? (Bonus points for a Python API call!)
To clarify, I'm asking for the hyphenated 8-hex-digit number that is displayed by the vol command in DOS:
C:\&gt;vol e:
Volume in Drive E is MYSDCARD
Volume Serial Number is E432-EF79

E432-EF79 is the VSN I'm looking for. It may sometimes be referred to as a UUID, though it's not 128 bits long.
On Mac I can mount the drive, and get its volume name, using commands like df. I can inspect it in DiskUtility, and see things like capacity and device name. But how do I get the VSN?
For a FAT32 formatted disk, in Terminal, the following example compound command will output its volume serial number:
var=&quot;$(sudo dd if=/dev/diskNs1 skip=67 bs=1 count=4 2&gt;/dev/null | hexdump -e '4/4 &quot;%X&quot;')&quot;; echo &quot;${var:0:${#var}/2}-${var:${#var}/2}&quot;


Replace N in /dev/diskNs1 with the correct disk number.

You can use the mount command or diskutil list to ascertain the disk number of the target disk.


Note that the target disk needs to first be unmounted before running the example compound command.

Assuming the target disk is mounted as /dev/disk6s1, in Terminal use:
diskutil unmountDisk disk6

After the target disk is unmounted, then use:
var=&quot;$(sudo dd if=/dev/disk6s1 skip=67 bs=1 count=4 2&gt;/dev/null | hexdump -e '4/4 &quot;%X&quot;')&quot;; echo &quot;${var:0:${#var}/2}-${var:${#var}/2}&quot;

For my test disk, a USB flash drive formatted FAT32, the output was:
18E4-4FA7

I confirmed this with the vol command in Windows and the blkid command in Linux, and the output of vol and blkid matched the output of the example compound command above.

Notes:
With FAT32 volumes, the Volume Serial Number is stored in the Boot Sector at offset 67 (0x43), and is four bytes long.
Interesting Reading: Volume Serial Numbers
and Format Date/Time Verification
There may be a way to format the output of the dd command with hexdump to avoid the rest of the compound command, however, I didn't want to take the time to figure it out and chose to use parameter expansion and shell arithmetic instead for the final formatting.