How do I find the UUID of a filesystem

Look up data on /dev/sda1:

topher@crucible:~$ sudo blkid /dev/sda1
/dev/sda1: UUID=”727cac18-044b-4504-87f1-a5aefa774bda” TYPE=”ext3″
Show UUID data for all partitions:

topher@crucible:~$ sudo blkid
/dev/sda1: UUID=”727cac18-044b-4504-87f1-a5aefa774bda” TYPE=”ext3″
/dev/sdb: UUID=”467c4aa9-963d-4467-8cd0-d58caaacaff4″ TYPE=”ext3″
Show UUID data for all partitions in easier to read format: (Note: in newer releases, blkid -L has a different meaning, and blkid -o list should be used instead)

topher@crucible:~$ sudo blkid -L
device     fs_type label    mount point    UUID
——————————————————————————-
/dev/sda1 ext3             /              727cac18-044b-4504-87f1-a5aefa774bda
/dev/sdc  ext3             /home          467c4aa9-963d-4467-8cd0-d58caaacaff4
Show just the UUID for /dev/sda1 and nothing else:

topher@crucible:~$ sudo blkid -s UUID -o value /dev/sda1
727cac18-044b-4504-87f1-a5aefa774bda

The easiest way to do this for ext2/ext3/ext4 is:  /sbin/tune2fs -l /dev/sda1

The recommended way to do this is to do  : sudo vol_id -u /dev/sda2

As noted in comments to this question, vol_id may not be in your path. On ubuntu it is in /sbin so the above will work. For fedora it appears to need

sudo /lib/udev/vol_id -u /dev/sda2

To get the GUID of partition 1 on GPT formatted disk /dev/sda, as well as its partition label and so on:

sudo sgdisk -i 1 /dev/sda
or all with:

ls -l /dev/disk/by-partuuid

Assuming you want the UUID for sda1, you could try something like this:

for v in /dev/disk/by-uuid/* ; do echo “`readlink $v`: $v” | grep ../sda1 | cut -d\: -f2 | cut -d/ -f5 ; done
Adjust sda1 accordingly. To get the UUIDs for all partitions, drop the greps and cuts, a la:

for v in /dev/disk/by-uuid/* ; do echo “`readlink $v`: $v” ; done
Sample output for sda1 on my desktop:

[mihailim@home ~]$

for v in /dev/disk/by-uuid/* ; do echo “`readlink $v`: $v” | grep ../sdb3 | cut -d\: -f2 | cut -d/ -f5 ; done
dc8c49f1-e2dc-46bc-ba02-013f26c85f70

You can also use this to print all the UUIDs:

for disk in /dev/disk/by-uuid/*; do
    basename “$(readlink “$disk”)”
    basename “$disk”
    echo
done
or this arguably simpler command, replacing sda1 with the device you’d like to search for:

disk=sda1
find /dev/disk/by-uuid -type l -exec sh -c “readlink {} | grep -o $disk && basename {}” \;
an adaptation of the second method to print all UUIDs:

find /dev/disk/by-uuid -type l -exec sh -c ‘basename $(readlink {}); basename {}; echo’ \;