Linux: Get UUID from Disk

Objective: Map a UUID (universally unique identifier ) to a device and vice versa on Linux.

A UUID is a practically unique (rather than guaranteed unique) 16-octet (or 128-bit) value. On Linux, the UUID may be used by mount, fsck, tune2fs, /etc/fstab (and possibly others) by specifying UUID=uuid instead of a block special device name like /dev/sda1.

There are a few methods to determine the UUID used for a disk or partition. The first is to list the files in /dev/disk/by-uuid/ directory.

But, by using the above method, I could not find the UUID of volumes that are managed by LVM (logical volume manager).

The next method is to use the tune2fs for disks on ext2/ext3/ext4 filesystem. To get the UUID of /dev/sda1, use the following syntax.

The third method is to use the blkid command can also be used to get the UUID of a disk or partition. To get the UUID of a specific device, use the following syntax.

If you have the UUID and want to map it to a device, run blkid using the following syntax.

To probe all known filesystems and devices, run blkid without any arguments and filter by UUID. Use “blkid -k” to print the supported list of filesystems.

You can see from the above output that blkid also handle devices that are part of LVM.

ibrahim = { interested_in(unix, linux, android, open_source, reverse_engineering); coding(c, shell, php, python, java, javascript, nodejs, react); plays_on(xbox, ps4); linux_desktop_user(true); }