Skip to content
Advertisement

Immutable names in /dev/disk

There are four entries in /dev/disk which I am interested in.

  1. by-id
  2. by-label
  3. by-path
  4. by-uuid

Which of the entries contain immutable names for physical drives? By immutable, I mean that the name shouldn’t change if I

  1. change the usb/pci port used to connect to the drive.
  2. destroy and create partitions (GPT).
  3. move from one computer to another (external hard-drive).

For example, /dev/sda can change to /dev/sdb if a different flash drive is connected. But the UUID stays the same. I don’t mind if a partition’s path changes (I think the UUID changes if you destroy and then recreate a partition), but the complete physical drive must stay at the same location (/dev/sdX may change, but the UUID doesn’t when the usb port is changed).

Please suggest relevant tags.

Edit
Can you say the same for partlabel and partuuid?

Advertisement

Answer

In short: you can use by-label or by-uuid to keep names immutable.

In detail:
Disk names (/dev/sdX) are given by kernel based on controller priority (master/slave) disk attached to. If you are moving disk from one USB port to another, for kernel it is like switching a controller. This is why names are changed from /dev/sda to /dev/sdb.
The directory /dev/disk is related to filesystem located on the disk. Label and uuid are filesystem attributes which are given on filesystem creation and can be changed after.
They are immutable and can survive:

  • disk migration from one computer to another.
  • disk migration from one controller to another on same computer.

However by-label and by-uuid will not survive if you destroy the partition, but the same label, uuid names can be given upon filesystem creation. So newly created filesystem will be mounted at same mount point.
I personally prefer to use by-label as it supported by many filesystems, short and descriptive.

More information about persistent block device naming.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement