Exactly what part of the disk is a UUID stored on? MBR? Somewhere within the partition? Is it a calculated value, or randomly generated and recorded?
3 Answers
The UUID is stored in the superblock (of which there are many copies in case one gets damaged). The value itself is generated using libuuid, which is part of the e2fsprogs suite. There are many libraries for generating UUIDs; RFC4122 is a good place to start as it describes the more commonly used technique and includes reference code.
Here's a couple of links that may help - they are specific to ext2, but other variants should also have a similar place where they store the uuid:
- 6,929
There seems to be a massive confusion. The "partition UUIDs" are indeed stored inside a partition entry but are only supported by GPT partition layout. However, when someone referred a "partition UUID", most often they actually meant a "filesystem UUID". The reason for that confusion is that MBR was for a long time the de-facto standard for partition tables layout and it didn't support UUIDs nor labels. Those were implemented instead by filesystems. And since filesystems typically covered a single whole partition, by referring to a partition UUID/label you were unambiguously referring to the FS UUID/label. Times have changed though. So the current state of things:
Filesystem UUID: a UUID stored inside a filesystem on the partition. This answer already covered that part, I don't have much to add.
lsblkrefers to it asUUIDFilesystem label: a label stored inside a filesystem on the partition.
lsblkrefers to it asLABELPartition UUID: a "unique partition GUID" that is stored inside every GPT partition entry, has size of 16 bytes. Not to be confused with "partition type GUID".
lsblkrefers to it asPARTUUIDPartition label: an arbitrary text stored inside every GPT partition entry, up to 36 characters in UTF-16 (yeah, odd encoding choice ♂️ Might be because GPT first appeared in late 1990s)
lsblkrefers to it asPARTLABEL
- 416
There are many ways to get the UUID of a partition, but by far the simplest way is to look in the /dev/disk/by-uuid/ folder. By example,
[pobega@greedo]$ **ls -l /dev/disk/by-uuid/**
lrwxrwxrwx 1 root root 10 2009-08-26 17:13 02ce3c1b-8893-402a-9e12-c01ac752ac3b -> ../../sda2
lrwxrwxrwx 1 root root 10 2009-08-26 17:13 2dcd156b-7ec6-4bf5-b1a2-dd4f5fb5082a -> ../../sdb3
[...]
Each file is a symlink to the partition that it is the UUID of (I apologize if that sentence is tough to comprehend, but it's a tough concept to put into words).
- 944