I'm running Ubuntu, and want to find out the UUID
of a particular filesystem (not partition). I know I can use e2label /dev/sda1
to find out the filesystem label, but there doesn't seem to be a similar way to find the UUID
.
I'm running Ubuntu, and want to find out the UUID
of a particular filesystem (not partition). I know I can use e2label /dev/sda1
to find out the filesystem label, but there doesn't seem to be a similar way to find the UUID
.
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:
Show UUID data for all partitions:
Show UUID data for all partitions in easier to read format: (Note: in newer releases,
blkid -L
has a different meaning, andblkid -o list
should be used instead)Show just the UUID for /dev/sda1 and nothing else:
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:
or all with:
To boot with the root of the file system being on a certain partition you would use the linux kernel parameter syntax of:
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
orroot=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=
androot=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
The script-clean way to do this which works on any type of filesystem is:
Or, given the mountpoint (or any file within it):
The output is the UUID, the whole UUID, and nothing but the UUID.
The easiest way to do this for ext2/ext3/ext4 is:
The recommended way to do this is to do
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
If other distributions have vol_id in other places then post a comment and I'll add it to this answer.
This seems to work for me:
Assuming you want the UUID for sda1, you could try something like this:
Adjust sda1 accordingly. To get the UUIDs for all partitions, drop the greps and cuts, a la:
Sample output for sda1 on my desktop:
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.
You can also use this to print all the UUIDs:
or this arguably simpler command, replacing
sda1
with the device you'd like to search for:an adaptation of the second method to print all UUIDs:
The above seems to work on most (all I have found) Linux systems over many years. It may have flaws, I don't know. I would prefer to get the serial number but ... this is the UUID of the root filesystem.
If anyone has a way to get the serial number without needing to be root (as mine is) and not installing "unusual" packages that are different in different versions of Unix I would appreciate it - always can learn something. And I am aware I am mixing things - the is the root file system UUID, not a disk.
The purpose, BTW, is to generate a unique number per machine that cannot be modified (like a disk serial number and like MAC addresses once were long ago).
It is used for encoding of software to a single machine. MAC address was fine until they allowed them to be virtual ... some sleazy customers have simply set their MAC address to a constant (on different networks of course) and avoided paying me.
In AIX there is a single call to get one number that identifies the machine. It does not care if the hardware changes or software updates occur so I have no idea how they do it ... If the motherboard changes, then the number changes, so I think they hide it there. And that is beyond rare.
The simplest and best way to find the UUID of a filesystem