What UUIDs Are and How To Use Them in Ubuntu

If you tried installing or upgrading Ubuntu recently, you probably noticed that all the storage devices are now using UUID – Universally Unique IDentifiers. I'm not claiming to know everything there is to know about UUIDs, but have become quite comfortable managing them lately, so hopefully this post will help you achieve the same.

What is a UUID exactly?

UUID is a Universally Unique IDentifier. It's a identification code given to each storage device you have on your system, aimed to help you uniquely identify each device no matter what.

UUIDs can be used to identify DVD drives, removable media (USB flashsticks) and each partition on any of your hard drives.

This is how a typical UUID looks:


Why use UUID?

Reason 1: Truly unique identification

UUID is the only way to guarantee you recognize the same drive or partition no matter what. For example, if you introduce to your system another hard drive, this might upset quite a few things, starting with the way your system boots up (or stops booting up upon the new drive introduction). Using UUID helps remedy most of such things.

Reason 2: Device names are not always persistent

Automatically assigned device names in your system are not consistent, they are according to the order of loading the kernel modules up during (most usually) the startup time, and thus the names will look different if you boot with one of your USB flashsticks attached and then reboot after you plug it out.

Generally, I've also found UUIDs really useful for mounting my removable media – I have a USB reader, one of the 24-in-1 kinds – it supports various types of cards and I use UUID to always mount the same card at the same location.

Reason 3: Most critical functionality of your Ubuntu system already depends on UUIDs

GRUB – your boot loader – relies on UUIDs as well. If you look into /boot/grub/menu.lst file, you'll find something similar to this:

title Ubuntu hardy (development branch), kernel 2.6.24-16-generic
root (hd2,0)
kernel /boot/vmlinuz-2.6.24-16-generic root=UUID=c73a37c8-ef7f-40e4-b9de-8b2f81038441 ro quiet splash
initrd /boot/initrd.img-2.6.24-16-generic

List UUIDs for all your devices

If you are using one of the recent releases of Ubuntu (UUIDs have been there since Edgy), you can use the blkid command to get a list of all the drives and partitions along with their UUIDs:

ubuntu# blkid
/dev/sda1: UUID="2220CF8220CF5B83" TYPE="ntfs"
/dev/sda2: UUID="48E81F29E81F14B2" LABEL="DRIVE-D" TYPE="ntfs"
/dev/sdb1: UUID="c73a37c8-ef7f-40e4-b9de-8b2f81038441" SEC_TYPE="ext2" TYPE="ext3"
/dev/sdb5: TYPE="swap" UUID="abe7529e-dcd5-4afc-b714-05569dbcd30b"
/dev/sdb6: UUID="f34c8c7c-a020-4a14-8c97-257180240250" SEC_TYPE="ext2" TYPE="ext3"
/dev/sdb7: UUID="8fa274ca-5b22-411f-b5da-7469c1f276da" SEC_TYPE="ext2" TYPE="ext3"
/dev/sdc1: UUID="1e36f323-c4e5-4f55-ba0a-838643550bf9" TYPE="ext3" SEC_TYPE="ext2"
/dev/sdc2: UUID="83aa92e4-4df4-4aab-80f3-9bbb447e0459" TYPE="ext3" SEC_TYPE="ext2"

As you can see, I've still got a few NTFS partitions as I'm slowly migrating my data from Windows after my switch to Ubuntu desktop a couple months ago.

Get UUID for a particular device

If you know a device name and just want to confirm the UUID for it to later use it in /etc/fstab, here's how you can do it using vol_id command:

ubuntu# vol_id -u /dev/sdb1

That's all I can think of so far. I know a few more things about UUID which I'll share in a separate post, but it's a start.

Have you got any more great ideas and tips for UUID? Let me know and I'll be sure to share them with others in the future posts.

Related books

If you want to learn more, here's a great book:


Ubuntu Kung Fu

See also:

  • redhat based distro's use labels instead of uuid's. this is such a bad way to do things…. uuid's simply rock.

  • Gleb Reys

    Hey Stan,
    Thanks for a comment!

    Yes, labels are available in Ubuntu as well, and they're somewhat better than using device names, but still not as good as UUIDs.

  • Hey Gleb!
    I have a minor addition to your post. GRUB doesn't know anything about UUIDs. The only UUIDs in the GRUB configuration are in the kernel command line – they aren't parsed by GRUB but passed directly to kernel after it is loaded.

    Unfortunately, grub still uses BIOS drive numbers (see the line "root hd(0, 1)"). 0 means the first BIOS drive, and 1 means second partition on that drive. So if you add a new hard drive to your system, BIOS may renumber the disks (this is likely if you add PATA disk to a bunch of SATA disks, or vice versa) and the system will become unbootable.

    In this case, type 'e' key when grub is loaded, select line 'root hd(0,1)' (or whatever drive and partition numbers you have), type 'e' again, and try increasing or decreasing drive number. Press Enter when you finished editing, and then press 'b'. If you guessed the BIOS drive number, the system will boot fine – no need to alter other parameters because kernel will find the root filesystem by UUID. 🙂

  • Gleb Reys

    Thanks for a really useful comment – good to know, especially BEFORE adding new drive to one's PC 🙂

  • Embedded

    Speaking of UUID and Grub on SuSE the Grub boot knows about UUID as does /etc/fstab.

    If you clone a Hard Drive better edit these for the new one because they will NOT be right on it eg. Toshiba 100GB hard drive to Toshiba 320GB hard drive. Best to rename all to sda0-whatever from UUID. (you can do that on the original too)

    Been There done that.

  • Anon

    UUIDs suck big time. They are hard to find out, keep changing all the time and GRUB doesn't use them. Linux developers are just insane to have introduced this.

  • Wim

    If these UUIDS are considered unique then why the heck do I get the same UUID all of a sudden. For some weird reason some of the UUIDs got screwed up.

    sudo blkid
    /dev/sda1: UUID="cde9bfc0-4c4f-405d-8729-95c0624cd3b3"
    /dev/sda2: TYPE="swap" UUID="19233dcb-6ae3-4b5f-a926-39e1909689c6"
    /dev/sdb1: UUID="cd79f6ab-6770-4e6c-a4ad-15db909abe02"
    /dev/sdc1: UUID="e7041c14-3952-4af6-8d98-fddc8e9313b9"
    /dev/sdd1: UUID="7bfd287a-9bab-4ef0-9e35-8931dba74f91"
    /dev/sde1: UUID="740b0350-af69-4d23-83ec-31b6f6e8b4ce"
    /dev/sdf1: UUID="740b0350-af69-4d23-83ec-31b6f6e8b4ce"

    Why oh why are these id's NOT unique?
    Reason #1 is not a correct argument if I look at this 🙂

  • Thanks for the info. It came in handy after repartitioning my two drives.

  • electronico

    Might your devices /dev/sde1 and /dev/sdf1 have been in a RAID1 or cloned ?
    This happened to me …

  • Pingback: Ubuntu Karmic Koala: Upgrading Jaunty Jackalope « Curly Braces()

  • Keith A

    Wim, it looks to me as if your sfd1 is a partition within the sde1 partition (using the same mounting point)

    I could be mistaken but that's my take on it.
    Try looking at your partitions with a LiveCD's graphical partition tool, it may help to visualize it.

  • anonymoose

    If you clone a partition's filesystem, the UUID of the original partition will be tacked on to the new partition as the cloned filesystem is copied over.

    You can then generate a new UUID for an Ext2 or Ext3 partition using

    tune2fs -U random /dev/sdax

    (where /dev/sdax is the number of the new partition)

    Be sure to copy the new UUID, as displayed by
    sudo blkid

    to the GRUB (Legacy) /boot/grub/menu.lst and to /etc/fstab

    Alternatively, you could generate a new UUID with

    and copy it to the menu.lst and fstab files and to the partition with

    tune2fs -U xxxxxx-xxxx /dev/sdax

    where xxxxx-xxxx stands for the newly generated UUID.

  • Anon is right! what good does uuid if you can not make any backups/clones from harddisks anymore without starting to "code" before. Linux should try to be more userfriendly if it want to spread itself

  • Anteaus

    Windows admins are only too familiar with situations where a device, service or account has to be reinstalled, and no matter how meticulously it is configured, the replacement simply will not work. This is almost always due to GUIDs, which are similar in principle to UUIDs.

    Random identifiers are one of the worst ideas ever introduced to computing. A computer is supposed to be predictable, not a fruitmachine emulation.