Howto get the UUID of a hard disk

Wednesday, 14th October 2009, 1201hrs jw Linux

What is the UUID?

The UUID library, present in all Linux systems, is used to generate unique identifiers for objects that may be accessible beyond the local system. The UUIDs generated by this library can be reasonably expected to be unique within a system, and unique across all systems. They could be used, for instance, to generate unique HTTP cookies across multiple web servers without communication between the servers, and without fear of a name clash. The UUIDs are also used to identify the hard disks on your Linux box.

Retrieve the UUID of your disk using blkid

The blkid program can be used to determine the type of content (e.g. filesystem, swap) a block device holds, and also attributes (tokens, NAME=value pairs) from the content metadata (e.g. LABEL or UUID fields).

user@box:~$ blkid /dev/sda5
/dev/sda5: UUID="21fb314a-b170-42b4-960a-07d7930b693f" TYPE="ext3"
The UUIDs of your disks can also be found in /dev/disk
user@box:~$ ls -al /dev/disk/by-uuid
total 0
drwxr-xr-x 2 root root 120 2009-10-14 10:31 .
drwxr-xr-x 5 root root 100 2009-10-14 10:31 ..
lrwxrwxrwx 1 root root  10 2009-10-14 10:31 0B7E-3FC3 -> ../../sda7
lrwxrwxrwx 1 root root  10 2009-10-14 10:31 21fb314a-b170-42b4-960a-07d7930b693f -> ../../sda5
lrwxrwxrwx 1 root root  10 2009-10-14 10:31 50340AA1340A8A64 -> ../../sda1
lrwxrwxrwx 1 root root  10 2009-10-14 10:31 9e83c2fe-b180-4b46-8b1c-b21eb1634895 -> ../../sda6
Use the vol_id command...

...when you want to see even more info on the hard disk:

user@box:~$ sudo vol_id /dev/sda5
ID_FS_USAGE=filesystem
ID_FS_TYPE=ext3
ID_FS_VERSION=1.0
ID_FS_UUID=21fb314a-b170-42b4-960a-07d7930b693f
ID_FS_UUID_ENC=21fb314a-b170-42b4-960a-07d7930b693f
ID_FS_LABEL=
ID_FS_LABEL_ENC=