Thursday, December 05, 2013

Disk UUID and how to get it

UUID stands for Universally Unique Identifier. UUID is an identifier standard userd in OSF. Unique should be taken to mean "practically unique" rather than "guaranteed unique". It is possible for two differing items to share one UUID, but very very rare.

1 trillion UUIDs would have to be created every nanosecond for 10 billion years to exhaust the number of UUIDs. 

A UUID in its canonical form is represented by 32 hexadecimal digits, displayed in five groups separated by hyphens, in the form 8-4-4-4-12. An example of UUID is: 550e8400-e29b-41d4-a716-446655440000

In Linux, UUID can be used to identify a device independent form its mount point or device name. This becomes more important as many devices today support hot-plugging. It makes sense to use UUID in /etc/fstab to identifu a device.

There are several ways to get the UUID. The first one uses the /dev/ directory.
$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Sep  6 16:44 229e78c7-6de9-41d7-88e9-4b7ee43b1c83 -> ../../sdb1
lrwxrwxrwx 1 root root 10 Sep  6 16:44 2dbae694-32s9-4a03-b42a-7f85b9c8362a -> ../../sdc1
lrwxrwxrwx 1 root root 10 Sep  6 16:44 677ab919-522d-4506-85a7-33cb0717b94a -> ../../sde1
lrwxrwxrwx 1 root root 10 Sep  6 16:44 76bb9a66-b91a-42ff-9822-d8dfb7fabe78 -> ../../sda5
lrwxrwxrwx 1 root root 10 Sep  6 16:44 c7b16c21-76a2-48ad-84af-1666b7032919 -> ../../sda1
lrwxrwxrwx 1 root root 10 Sep  6 16:44 cd297f1f-b11f-4f87-a9a5-7a0f98f700eb -> ../../sdd1
lrwxrwxrwx 1 root root 10 Sep  6 16:44 e1e00fd2-bss2-4a09-8704-c7f6465a79ee -> ../../sda3
lrwxrwxrwx 1 root root 10 Sep  6 16:44 ecb3f1ae-baa6-4e7e-9c18-e9e9dfa8909b -> ../../sda2

The second way is to use the command "blkid" (command-line utility to locate/print block device attributes):
$ blkid -o list
device                                           fs_type         label            mount point                                          UUID
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
/dev/sda5                                        ext4                             /                                                    76bb9a66-b98a-42ff-9822-d8dfb7fabe78
/dev/sda1                                        ext4                             /boot                                                c7b16c21-76f2-48ad-84af-1666b7032919
/dev/sda2                                        swap                             <swap>                                               ecb3f1ae-bda6-4e7e-9c18-e9e9dfa8909b
/dev/sda3                                        ext4                             /tmp                                                 e1e00fd2-bb32-4a09-8704-c7f6465a79ee
/dev/sdb1                                        ext4                             /data1                                               229e78c7-6de9-41d7-88e9-4b7ee43b1c83
/dev/sde1                                        ext4                             /data4                                               677ab919-521d-4506-85a7-33cb0717b94a
/dev/sdd1                                        ext4                             /data3                                               cd297f1f-b52f-4f87-a9a5-7a0f98f700eb
/dev/sdc1                                        ext4                             /data2                                               2dbae694-32c9-4a03-b42a-7f85b9c8362a

or you want to know a specific drive's uuid:

$ blkid /dev/sdc1
/dev/sdc1: UUID="2dbae694-32c9-4a03-b42a-7f85b9c8362a" TYPE="ext4"

How to change a device's UUID?
Following the steps below to change a device's UUID:
Generate a time-based UUID. This method creates a UUID based on the system clock plus the system's ethernet hardware address, if present.
# uuidgen -t
or
Generate a random-based UUID. This method creates a UUID consisting mostly of random bits. It requires that the operating system have a high quality random number generator, such as /dev/random.
# uuidgen -r
# tune2fs /dev/hdaX -U numbergeneratedbyuuidgen
# blkid /dev/hdaX

1 comment:

Marshall628 said...

Nice Blog! Just found it.