Explainer: UUIDs

There are many occasions when you need a unique identifier that you can use to refer to a specific item, whether it’s an entry in a database, an APFS volume, a user, or even a Mac. The best way to ensure it remains unique, so it can’t be confused with others, is to use a very large number and assign values randomly. At its heart, a Universally Unique Identifier is just that, a 128-bit number, with several mechanisms for randomising them as necessary. As humans aren’t good at reading such huge numbers, they’re usually expressed as a series of 32 hex digits, broken with hyphens into five groups, such as 532ABCA9-287D-4DD6-9B5F-F327C3C3F291.

Where

You’ll find them throughout Mac hardware, macOS, Apple and third-party apps, Apple devices, Windows (where they’re often referred to as GUIDs), and Linux, but they’re not yet being tattooed onto the soles of babies’ feet. There are even conspiracy theories about how Apple and others use them to encode private information such as bank card details, which are of course arrant nonsense.

If you’d like to start collecting UUIDs, here are some places to begin with:

  • boot UUID, assigned uniquely to every boot from the start
  • file system UUIDs on every volume group, volume, APFS container, and snapshot, and more
  • user UUID, assigned to each new user when that account is created
  • hardware UUID for each Mac, although those are different, as explained below
  • inside many databases to identify records, and in structures used in SwiftUI.

If you’re looking for more, you can generate your own using the uuidgen command tool in Terminal, and if you’ve a few million years to while away you can keep using that to see if you can create two that are the same. In Swift code, there’s a UUID struc available in 16 UInt8 numbers, or expressed using standard string representation.

Versions

Since their introduction in the 1980s, UUIDs have adopted several versions, of which you should encounter just three in macOS and Macs: version 4, by far the most common, version 5 and special fixed UUIDs. You can tell these apart as in the first two the version number is given as the first character of the third block of hex numbers, M in xxxxxxxx-xxxx-Mxxx-xxxx-xxxxxxxxxxxx.

Special Fixed UUID

You’re most likely to encounter this in the UUID used to identify the file system for each partition in a GUID Partition Table (GPT), for a disk. These are fixed identifiers, and for APFS it’s 7C3457EF-0000-11AA-AA11-00306543ECAC, while 48465300-0000-11AA-AA11-00306543ECAC is HFS+.

macOS also uses some special fixed UUIDs for particular purposes, among them user IDs for daemons and special users. These have the form FFFFEEEE-DDDD-CCCC-BBBB-AAAA00000xxx where the last three characters vary between IDs. Other user IDs should follow version 4 conventions, though.

Version 5

These are most commonly seen in the hardware identifier for a Mac. Officially they’re generated by hashing a namespace identifier and name using SHA-1. Because these don’t include any randomisation, using the same identifier and name will always create the same UUID, which is why they’re used to identify Macs. However, because they’re hashed, you can’t derive the name from the UUID, even if you know the namespace identifier.

Version 4

These come in two variants, distinguished by the first character of the fourth block of hex numbers, N in xxxxxxxx-xxxx-4xxx-Nxxx-xxxxxxxxxxxx. macOS normally uses variant 1, which sets N to be 8, 9, A or B. Other parts of the UUID are supposed to be generated as random values, ensuring the chance of two identical UUIDs being generated is extremely remote. To have a 50% chance of that occurring, you’d have to generate a billion version 4 UUIDs every second for about 86 years, so that’s not something you’re ever likely to encounter on your Mac.

That said, modern Macs running current apps in recent macOS certainly generate ample UUIDs. My log browser LogUI, for example, assigns a version 4 UUID to every entry in the log extracts it displays, although those aren’t shown. Next time you get 5,000 log entries, reflect on the fact that’s another 5,000 UUIDs gone. It’s a good thing that no government has yet thought of taxing UUIDs.

Reference

Wikipedia