To get the UUID of a block device, use blkid
:
$ blkid /dev/sdb1
/dev/sdb1: UUID="1c46a3c1-cbe7-4bb6-a412-445f317e2b5d" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="7f943a21-be92-304f-8bae-45aa7c4b0c78"
There are typically two UUIDs given, UUID and PARTUUID. UUID is a property of the filesystem, while PARTUUID is a property of the GPT partition table. In a lot of cases, you can use either/or but keep in mind your future use cases before settling on one or the other. For example:
- If you might be cloning a filesystem on the same host, this will result in a duplicate UUID but not a duplicate PARTUUID. If there are two filesystems with the same UUID present on the system, Linux will refuse to guess which one you mean.