Understanding UUID assignment

Owen

A UUID (universal unique identifier) is a 128 bit code which is used to identify block (storage) devices. Firstly, is this all UUIDs are used for?

How does a device obtain its UUID?

Does it ever change? For instance, on each startup? When a new OS is installed?

How is a UUID generated? Is it random?

Most computers don't have more than 10 storage devices. Why the need for so many different names?

garethTheRed

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 tune2fs)

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.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related