Can anybody explain me how UUID (Universally unique identifier) of a partition is generated in Linux based distributions ?
Both UUID of GPT partitions, and UUID of filesystems, are generated randomly when the partition/filesystem is created. You can check that they're version 4 UUIDs.
An uuid is just formatted (hyphens at specific places) random bytes so there's nothing magical about it.
By glancing at the source, which you can get with
apt-get source libuuid1 if you're on a Ubuntu based distro, the uuid generation either uses truly random bytes (known to be rather slow -- you can get those by reading from the /dev/random special file) or time-based bytes (virtually instantaneous but not cryptographically secure).
UUID of a partition which generated in Linux distribution is version 4. The version 4 UUID is meant for generating UUIDs from truly-random or pseudo-random numbers. It is described in RFC 4122 .
At present in my Ubuntu 15.04 UUID version 4 is used for partitions.
Version 4 UUIDs use a scheme relying only on random numbers.
here 4 denotes the version number
x is any hexadecimal digit
y is one of 8, 9, A, or B
Random UUID probability of duplicates
Out of a total of 128 bits, two bits indicate an RFC 4122 ("Leach-Salz") UUID and four bits the version (0100 indicating "randomly generated"), so randomly generated UUIDs have 122 random bits. The chance of two such UUIDs having the same value can be calculated using probability theory (birthday paradox). Using the approximation
these are the probabilities of an accidental clash after calculating n UUIDs, with x = 2^122:
To put these numbers into perspective, the annual risk of a given person being hit by a meteorite is estimated to be one chance in 17 billion, which means the probability is about 0.00000000006 (6 × 10−11), equivalent to the odds of creating a few tens of trillions of UUIDs in a year and having one duplicate. In other words, only after generating 1 billion UUIDs every second for the next 100 years, the probability of creating just one duplicate would be about 50%.