UUID

From LQWiki
Jump to navigation Jump to search

This article is a stub and needs to be finished. Plunge forward and help it grow! This article only describes the use of UUIDs for the identification of filesystems and paritions.

A UUID or universally unique identifier is a label given to objects and used to refer to them to avoid collision with other objects.

Background

To create an extreme amount of entropy, UUIDs have 128 bits of random data. This makes it near impossible to regenerate the same label, even across millions of computers.

UUIDs are represented in 36-character strings. Here is an example of one:

b3c023f9-38d5-495e-a10d-edebc8ab57d9

Block Devices

UUIDs can be used to refer to block devices in Unix-like operating systems, such as in fstab(5) or crypttab(5), as a mismatch could lead to an unbootable system or data loss.

When creating a partition with, for example, fdisk(8), a UUID is generated and saved along with other metadata. Using lsblk(8), you can view the partitions and volumes of your system, along with their UUIDs:

$ lsblk -o NAME,UUID
NAME     UUID
sda      
sdb      
├─sdb1   6b4f9de0-4539-403a-841b-45961960dbb3
└─sdb2   d5616c8d-dfff-4366-8d9a-5e6892252829
  └─root fb955ac1-ea72-48e4-b7c0-ec98648a93de
sdc
├─sdc1   64A0-1B19
└─sdc2   12974f21-6ab1-4414-bf58-1477df30d725
sr0
...

Using UUIDs

When specifying a partition using its UUID, you will simply need to prepend "UUID=" before the UUID, in place of a direct path to its block device.

In fstab(5):

/dev/sdc2                                  /       xfs       defaults       0 1
    ↓
UUID=12974f21-6ab1-4414-bf58-1477df30d725  /       xfs       defaults       0 1

or, the Linux kernel's cmdline, through GRUB's configuration file:

GRUB_CMDLINE_LINUX="root=/dev/sdc2 video=1920x1080@60Mm ..."
    ↓
GRUB_CMDLINE_LINUX="root=UUID=12974f21-6ab1-4414-bf58-1477df30d725 video=1920x1080@60Mm ..."

See Also