The concept is described in RFC 4122 which defines the various algorithms for generating UUIDs. Variant 4 uses random numbers and is the most common.
UUIDs are used in many scenarios, a few examples are:
- Labelling partitions and filesystems is the most common usage within Linux
- Network Manager uses them to identify network devices and connections
- Hypervisors, such as Virtual Box and Qemu-KVM, uses them to identify VMs
- The are used within Microsoft Windows where they are knows as GUIDs
- They are used for uniqueness within databases
- They are used in software development
Within Linux, all distros come with the
util-linux package, which amongst other things has the
uuidgen command to generate UUIDs. This is a front-end to
libuuid which generates random UUIDs by default, or time-based if not enough entropy is available.
The utility you use to create a partition or filesystem will generate the UUID, which remains with that partition/filesystem until you either re-create them or explicitly change the UUID (for example with
UUIDs are used with filesystems and partitions in order to give them a consistent name (although a very long one). This avoids the scenario where the BIOS of UEFI firmware in a two HDD system lists hard disk so that your system disk is allocated
/dev/sda on one boot and allocated
/deb/sdb on the next (maybe the first disk was slower to start up on the second boot).
Using the traditional naming method, this would cause havoc in your
/etc/fstab file as your system would be looking in the wrong disk for partitions to mount. For example, here is my swap entry:
/dev/sda4 none swap defaults 0 0
If the disks had been allocated differently at boot, my system wouldn't find a fourth partition of type
swap on the non-system disk (OK, I'm on a laptop, so it hasn't got a second disk, but you get the point) and my swap would fail.
By labeling them with UUIDs, and using those within
/etc/fstab you're guaranteed that the correct filesystem will be mounted at all times. For example:
UUID=d8ab8967-f2de-4c76-902f-d8d9707c399e /media/files ext4 defaults 0 0
will always mount the partition with that UUID on
/media/files regardless of the order the BIOS (or UEFI firmware) labels them at boot.