How do I find the UUID of a filesystem

Solution 1:

Another command that might be available and also works quite well for this is 'blkid'. It's part of the e2fsprogs package. Examples of it's usage:

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

Solution 2:

For GPT Partitioned Disks Only

On a GPT formatted disk each partition is assigned a GUID, which is a form of UUID, though probably not what the original poster was referring to. Therefore this answer is probably less helpful to the original questioner. Nevertheless I believe there's an important distinction to be noticed.

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

To boot with the root of the file system being on a certain partition you would use the linux kernel parameter syntax of:

root=PARTUUID=87654321-4321-4321-abcd-123456789012

In this case you can specify just the beginning of the UUID--enough to be unique. This parameter is more primitive and can be understood by the kernel earlier in its boot process.


There's a difference in semantics between these:

A disk holds partitions, a partition holds a file system, a file system holds directories and files. For some set-ups and operating systems there are more layers.

The GUID UUID and associated label refer to a partition, but not the partition's contents. A new partition on the same disk, or a partition on a new disk will have a new GUID UUID. The same partition could hold one file system one day and another on a different day. It only exists for GPT formatted disks, but not for legacy partitioned disks. There's usually no more utility here than specifying root=/dev/sda1 or root=8:1.

The other current answers refer to the UUID of a file system in some containing partition. If the file system is copied, as a whole, to another partition or hard disk that value remains the same. This UUID is useful in finding a moved file system. Therefore this is probably more pertinent to most people. Linux kernel parameter root=UUID=87654321-4321-4321-a567-123456789012 refers to this.

I believe root=LABEL= and root=UUID= are implemented by early userspace, the init code I saw the other day on my system translated these parameters to /dev/disk/by-uuid and /dev/disk/by-label (links I believe are created by udev in userspace on my system).

[1] http://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/init/do_mounts.c#n183


Solution 3:

The script-clean way to do this which works on any type of filesystem is:

lsblk -no UUID <device-containing-FS>

Or, given the mountpoint (or any file within it):

lsblk -no UUID $(df -P <file> | awk 'END{print $1}')

The output is the UUID, the whole UUID, and nothing but the UUID.


Solution 4:

The easiest way to do this for ext2/ext3/ext4 is:

/sbin/tune2fs -l /dev/sda1

Solution 5:

The recommended way to do this is to do

sudo vol_id -u /dev/sda2

For more on using UUIDs, see this article (from ubuntu help, but should work for any linux distro using UUIDs).

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

If other distributions have vol_id in other places then post a comment and I'll add it to this answer.