Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I have always seen people discuss using UUIDs in hard drives instead of /dev/sdN.

What is the real benefit of using a UUID? Is it faster, more reliable, easier to remember (ha lol no), what?

And, isn't it possible to change a UUID? Is there a way to identify a drive (especially in GRUB) that can never change?

share|improve this question
    
Btw, you can also use labels in some cases. That is easier to remember, but can potentially be spoofed (since the user defines it oneself). –  Volodya Jan 23 at 5:48

3 Answers 3

up vote 5 down vote accepted

What is the real benefit of using a UUID?

Generally, the UUID is constant for the same drive/partition no matter what system it is attatched to.

The /dev/sdN naming scheme increments the final letter (N) for each device plugged in (a, b, c, d, etc.). This means that the /dev/sd identifier assigned to the device changes if it is attached in a different order.

And, isn't it possible to change a UUID?

Yes, see here.

Is there a way to identify a drive (especially in GRUB) that can never change?

That's what UUIDs are for. They're probably the most stable solution you can get.


Using UUIDs in scripts and the like

If you are instructed to perform a command like this:

dd if=/dev/sda of=/dev/null 

... you can replace /dev/sda with a file in /dev/disk/by-uuid/ to reference the disk by UUID instead of sdN.

Run these commands to get the UUIDs (and sdN notation) of drives on your system:

for disk in /dev/disk/by-uuid/*; do
    readlink -e "$disk"
    echo "${disk#/dev/disk/by-uuid/}"
    echo
done
share|improve this answer
1  
+1 for nice answer and formatting. –  Whaaaaaat Jan 23 at 5:50

It becomes important because numbers can, and sometimes do, change. That happens usually if you change the partition table in some way. For example you may have had 2 partitions: sda1 and sda2, you later delete sda1 and make two separate ones out of it. Normally fdisk will not change the number of sda2, but some other tools (gparted i believe) will, so now your sda2 becomes sda3, but it will still have the same UUID.

UUID is impossible to change without changing the actual partition, and if you do that, then it really isn't clear if you still want to mount that newly created one.

share|improve this answer

What is the real benefit of using a UUID? Is it faster, more reliable, easier to remember (ha lol no), what?

Here is a real life example of why you should be using UUIDs instead of /dev/XXX when mounting in fstab. (So yes, it is more reliable as the UUID won't change when a drive from the chain is out.)

The other well known real life situation where UUIDs come handy is at booting to identify the device which you want to boot in GRUB. Because without the UUID the drive numbering scheme is dependent on the BIOS boot-order and changing the boot-order in the BIOS can cause problems. (Say you were booting from a SATA drive, then you plugged in an ATA drive and changed the boot-order to first boot the ATA. After that you fromat the ATA drive (which is now not bootable) but not revert the boot-order. Your BIOS will boot the SATA drive as the ATA drive is not bootable but is is totally possibly that GRUB now won't find your drive if you aren't using UUIDs.) This is written in the GRUB's manual too here.

And, isn't it possible to change a UUID?

Yes you can change the UUIDs, but this doesn't defeat the purpose of the UUID. The purpose of the UUID is to be constant across reboots and across machines no matter what is the machine's setup or where you plug in the drive. The purpose is not that to give your drive an unchangeable name for its lifetime.

Is there a way to identify a drive (especially in GRUB) that can never change?

Technically for some of the drives it possible to identify them in a way that can never change as the drives have a World Wide Name and/or a serial number. Normally these values are not changeable and they are unique to the drive. (Technically it might be possible to change these values too.) You can view such info about your drive with e.g. sudo hdparm -I /dev/sda . (Likely that the mass manufactured cheap or not cheap USB pendrives/memory cards doesn't always have such identification.)

But these unique identifiers are for the drive and for the OS and for you the more important is a unique identifier for the partition, thats what the UUID is for. And since partitions are changeable on a drive of course the UUIDs are changeable too.

share|improve this answer

Your Answer

 
discard

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.