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:
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.
lsblk
refers to it asUUID
Filesystem label: a label stored inside a filesystem on the partition.
lsblk
refers to it asLABEL
Partition 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".
lsblk
refers to it asPARTUUID
Partition 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)
lsblk
refers to it asPARTLABEL
-
1IMO, this is the most precise answer. The GPT partition GUID, which you refer as Partittion UUID is stored at byte offset 56 inside the GPT header which is duplicated at the beginning and end of a GPT partition. A GPT partition has NO superblock as that is a filesystem concept. This link has good info: en.wikipedia.org/wiki/GUID_Partition_Table Jan 13 at 17:58
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).
-
I'm not interested in the UUID, but how those UUID to device mappings are built, so that I can restore Ubuntu from a full disk backup and expect it to boot.– jlduggerAug 27, 2009 at 4:10
-
@jldugger I presume you're interested in "filesystem UUIDs", and the answer might be different depending on a filesystem you're interested in. For example, when you create a swap partition with
mkswap
, there's just not much information to use in generation of a UUID. And as it's different each time for the same partition, it either includes a timestamp, or even completely random. Even if it's the timestamp, I doubt SWAP header includes timestamp (sounds like a waste of space), so you can't re-create UUID by knowing all fields but not the UUID itself. So… 🤷♂️– Hi-AngelDec 2, 2022 at 15:10