Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm running Ubuntu, and want to find out the UUID of a particular partition. I know I can use e2label /dev/sda1 to find out the partition label, but there doesn't seem to be a similar way to find the UUID.

share|improve this question
Thanks for all the answers, I'm sure I will use them all in different circumstances. –  Brad Gilbert May 5 '09 at 3:45
add comment

6 Answers

up vote 38 down vote accepted

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
share|improve this answer
On my Ubuntu computer, I don't need to use sudo. –  Brad Gilbert May 5 '09 at 3:28
Just typing blkid, got me exactly what I wanted, but not quite what I asked for. ( I'm accepting it anyway, because I am sure I will use it often ) –  Brad Gilbert May 5 '09 at 3:38
On newer versions of Ubuntu the equivalent command for blkid -L is now blkid -o list; the -L option has been changed to -L label to look up a device that uses the specified label. –  aculich Jan 29 '12 at 3:09
@aculich I've updated the answer to included the recent syntax for blkid. Thanks for mentioning it. –  Christopher Cashell Mar 27 '12 at 19:41
Excellent, I never knew about blkid; I've always just done ls -l /dev/disk/by-uuid. On Gentoo, blkid is in sys-apps/util-linux –  AdmiralNemo Mar 27 '12 at 23:48
show 1 more comment

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.

share|improve this answer
This doesn't work on my Fedora 10 laptop. –  Eddie May 2 '09 at 17:10
This is a much better solution than mine. Eddie, vol_id is located in /lib/udev. mish, could you edit your answer to prefix the full path in front of vol_id? /lib/udev isn't in root's path by default on any distribution I'm aware of. –  Mihai Limbăşan May 2 '09 at 17:13
"/lib/udev/vol_id /dev/sda2" appears to work. Few people will have /lib/udev in their path. –  Eddie May 2 '09 at 17:20
On my Ubuntu computer there is a symbolic link from /sbin/vol_id to /lib/udev/vol_id –  Brad Gilbert May 3 '09 at 16:59
Even though this is exactly what I asked for, blkid would have been more useful, when I went to edit /etc/fstab. –  Brad Gilbert May 5 '09 at 3:42
add comment

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

/sbin/tune2fs -l /dev/sda1
share|improve this answer
This will work provided your filesystem is formatted as ext2, ext3 or ext4. Most filesystems are one of these but not all. It will also not work for swap partitions. See my answer for a universal way. –  Hamish Downer May 2 '09 at 16:54
add comment

You can use the following to get the UUID for a particular drive,

sudo vol_id -u /dev/sda1

or you can use this to list all UUIDs for the attached media,

ls /dev/disk/by-uuid
share|improve this answer
add comment

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

Edit: Please note that this solution, while more contrived than the udev->vol_id one, does not require root privileges, will work on any post-2005 or so kernel, and relies on tools present in any Linux distribution which are by default in the path for any user.

share|improve this answer
This will work on any computer running a recent enough devfs. –  Eddie May 2 '09 at 17:13
add comment

You can also use this to print all the UUIDs:

for disk in /dev/disk/by-uuid/*; do 
    basename "$(readlink "$disk")"
    basename "$disk"

or this arguably simpler command, replacing sda1 with the device you'd like to search for:

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' \;
share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.