There are many ways to generate an Universally Unique Identifier or UUID in Linux. Not long after I wrote my post about my discoveries on DRBD with Corosync and iSCSI, I discovered that I have to define SCSI serial numbers for each of my LUNs.
I decided to have them randomly generated in order to make sure they’re unique. The easiest way is to generate a random UUID. In Linux, you have usually three ways of doing so.
The kernel random way
I chose to use the generator provided by the Linux kernel by using the
#!text /proc/sys/kernel/random/uuid file. The contents of the file are a simple UUID :
$ cat /proc/sys/kernel/random/uuid 4fe4772f-e88e-4e10-b072-189a6444fe2c
The uuidgen way
Another method of generating UUIDs is to use the
#!shell uuidgen utility,
provided by default in most distributions. This utility is able to
generate either random identifiers, or use time as a basis. It can be
used as follows :
# Generate a totally random UUID $ uuidgen 3de197c8-0da3-45e6-8928-11d2be1ec308 # Generate a time-based UUID $ uuidgen -t b5646b86-6616-11e4-8035-be3585e0bc43