Translation(s): English - Italiano - Português (Brasil) - Русский


Overview: UUIDs, Labels and fstab

Persistent device naming for block devices has been made possible by the introduction of udev and has some advantages over the use of traditional bus-based names such as /dev/hda1 or /dev/sda2.

While Linux distributions and udev are evolving and hardware detection is becoming more reliable, there are also a number of new problems and changes:

  1. If you have more than one disk controller (IDE or especially SCSI/SATA), or even if you just have variable numbers of removable USB/firewire storage devices attached from day to day, the order in which they are detected may not be deterministic. The result is that device names like /dev/sda1 and /dev/sdb1 may switch around randomly on each boot. Persistent naming allows you not to worry about this at all.

  2. For machines with IDE controllers (including for instance machines with all-SATA hard drives and just one IDE cdrom drive), the switch to a standard Squeeze kernel may cause trouble: with the introduction of the new libata PATA support, your IDE hdX devices will become sdX devices. Again, if you have persistent naming in place, you won't even notice. (The postinst for the package linux-base includes code to assist with the changeover, but it makes sense to get it sorted out and verified as working in advance.)

  3. Big machines, with many fast CPUs, and many Fiber Channel Host Bus Adapters, variable load/latency FC switches, SCSI controllers, and/or high-performance network cards, may have asynchronous timing issues when dealing with udev and multipath I/O, with almost unpredictable device detection order and automatic assignment of names during boot.

There are more reasons, but these are the most critical ones now and in the near future. That's why Debian encourages you to change your setup to persistent naming schemes, unless you are using LVM. LVM logical volumes should always be identified by logical volume name (/dev/mapper/name).

The Four Different Schemes for Persistent Naming

Via UUIDs

UUID stands for Universally Unique Identifier and is a mechanism to give each filesystem a unique identifier. All Linux filesystems support filesystem UUIDs; FAT and NTFS filesystems don't support true UUIDs, but are still listed in /dev/disk/by-uuid with a unique identifier:

$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 Oct 16 10:27 2d781b26-0285-421a-b9d0-d4a0d3b55680 -> ../../sda1
lrwxrwxrwx 1 root root 10 Oct 16 10:27 31f8eb0d-612b-4805-835e-0e6d8b8c5591 -> ../../sda7
lrwxrwxrwx 1 root root 10 Oct 16 10:27 3FC2-3DDB -> ../../sda6
lrwxrwxrwx 1 root root 10 Oct 16 10:27 5090093f-e023-4a93-b2b6-8a9568dd23dc -> ../../sda2
lrwxrwxrwx 1 root root 10 Oct 16 10:27 912c7844-5430-4eea-b55c-e23f8959a8ee -> ../../sda5
lrwxrwxrwx 1 root root 10 Oct 16 10:27 B0DC1977DC193954 -> ../../sdb1
lrwxrwxrwx 1 root root 10 Oct 16 10:27 bae98338-ec29-4beb-aacf-107e44599b2e -> ../../sdb2

As you can see, the FAT and NTFS filesystems have shorter names (sda6 and sdb1), but are still listed by UUID. The point of the 32-digit base-62 strings is to make collisions astronomically unlikely; if it happened that sda1 and sda2 had the same UUID the system would fail to boot.

LVM snapshots will result in duplicate UUIDs, however.

Via Labels

Almost every filesystem type can also have a label. All those that have one are listed in the /dev/disk/by-label directory:

$ ls -l /dev/disk/by-label
lrwxrwxrwx 1 root root 10 Oct 16 10:27 data -> ../../sdb2
lrwxrwxrwx 1 root root 10 Oct 16 10:27 data2 -> ../../sda2
lrwxrwxrwx 1 root root 10 Oct 16 10:27 fat -> ../../sda6
lrwxrwxrwx 1 root root 10 Oct 16 10:27 home -> ../../sda7
lrwxrwxrwx 1 root root 10 Oct 16 10:27 root -> ../../sda1
lrwxrwxrwx 1 root root 10 Oct 16 10:27 swap -> ../../sda5
lrwxrwxrwx 1 root root 10 Oct 16 10:27 windows -> ../../sdb1

While recognisable words may be used as labels, you need to exercise caution to prevent name collisions; consider the possibility that you might have random USB/firewire drives plugged in at reboot. LVM snapshots will also result in duplicate labels.

You can change the labels of your filesystems using these commands:

Type

Command

Notes

EXT3:

e2label /dev/XXX <label>

also applies to EXT2/EXT4

FAT/VFAT:

dosfslabel /dev/XXX <label>

bug #506786 in Lenny; or mlabel in mtools

JFS:

jfs_tune -L <label> /dev/XXX

NTFS:

ntfslabel /dev/XXX <label>

or change it under Windows

ReiserFS:

reiserfstune -l <label> /dev/XXX

swap:

mkswap -L <label> /dev/XXX

but see below on swapoff/swapon procedure

XFS:

xfs_admin -L <label> /dev/XXX

Via Hardware IDs

by-id creates a unique name depending on the hardware serial number. These are intended to be immutable for a given hardware configuration.

#  ls -l /dev/disk/by-id/
total 0
lrwxrwxrwx 1 root root 10 2010-10-20 13:52 dm-name-grupo1-lvstripe1 -> ../../dm-8
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-name-mpath0 -> ../../dm-0
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-name-mpath1 -> ../../dm-1
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-name-mpath2 -> ../../dm-2
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-name-mpath3 -> ../../dm-3
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-name-mpath4 -> ../../dm-4
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-name-mpath5 -> ../../dm-5
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-name-mpath6 -> ../../dm-6
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-name-mpath7 -> ../../dm-7
lrwxrwxrwx 1 root root 10 2010-10-20 13:52 dm-uuid-LVM-OaDwNcuwdzuuZYAcrbeKNdYsE237BKX2YIEdUN5CsSgeU7WNn5dhtiQPBP9uHU25 -> ../../dm-8
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-uuid-mpath-36005076308ffc36c000000000000000c -> ../../dm-0
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-uuid-mpath-36005076308ffc36c000000000000000d -> ../../dm-1
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-uuid-mpath-36005076308ffc36c000000000000000e -> ../../dm-2
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-uuid-mpath-36005076308ffc36c000000000000000f -> ../../dm-3
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-uuid-mpath-36005076308ffc36c0000000000000112 -> ../../dm-4
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-uuid-mpath-36005076308ffc36c0000000000000113 -> ../../dm-5
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-uuid-mpath-36005076308ffc36c0000000000000114 -> ../../dm-6
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 dm-uuid-mpath-36005076308ffc36c0000000000000115 -> ../../dm-7
lrwxrwxrwx 1 root root  9 2010-10-20 13:51 scsi-360026b9038e49f001270c8b707980d5c -> ../../sda
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 scsi-360026b9038e49f001270c8b707980d5c-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 scsi-360026b9038e49f001270c8b707980d5c-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 scsi-360026b9038e49f001270c8b707980d5c-part3 -> ../../sda3
lrwxrwxrwx 1 root root  9 2010-10-20 13:51 scsi-36005076308ffc36c000000000000000c -> ../../sdr
lrwxrwxrwx 1 root root  9 2010-10-20 13:51 scsi-36005076308ffc36c000000000000000d -> ../../sdc
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 scsi-36005076308ffc36c000000000000000e -> ../../sdab
lrwxrwxrwx 1 root root  9 2010-10-20 13:51 scsi-36005076308ffc36c000000000000000f -> ../../sdu
lrwxrwxrwx 1 root root  9 2010-10-20 13:51 scsi-36005076308ffc36c0000000000000112 -> ../../sdn
lrwxrwxrwx 1 root root  9 2010-10-20 13:51 scsi-36005076308ffc36c0000000000000113 -> ../../sdo
lrwxrwxrwx 1 root root  9 2010-10-20 13:51 scsi-36005076308ffc36c0000000000000114 -> ../../sdp
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 scsi-36005076308ffc36c0000000000000115 -> ../../sdag
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 scsi-mpath0 -> ../../dm-0
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 scsi-mpath1 -> ../../dm-1
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 scsi-mpath2 -> ../../dm-2
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 scsi-mpath3 -> ../../dm-3
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 scsi-mpath4 -> ../../dm-4
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 scsi-mpath5 -> ../../dm-5
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 scsi-mpath6 -> ../../dm-6
lrwxrwxrwx 1 root root 10 2010-10-20 13:51 scsi-mpath7 -> ../../dm-7

Via sysfs Paths

by-path creates a unique name depending on the shortest physical path (according to sysfs). Both contain strings to indicate which subsystem they belong to and thus are not suitable for solving the problems mentioned in the beginning of this article. They won't be discussed any further here.

Preparing for Persistent Naming

You can get a basic overview of which devices are associated with which persistent names simply by invoking

$ ls -lR /dev/disk

but there's also a handy new blkid command (which is in /sbin, but doesn't require root privileges). It gives various kinds of useful output, the simplest being:

$ /sbin/blkid
/dev/sda1: LABEL=Root UUID="87f2b245-6ab3-4021-bf07-d069b4d387a1" TYPE="ext3"
/dev/sda2: TYPE="swap"
/dev/sda3: LABEL=Home UUID="a6f7a63f-71ac-4361-b49a-39d62b06f18a" TYPE="ext3"

As you can see, the swap partition here does not have a UUID or label; the Debian Lenny installer used a version of partman that did not set these for swap partitions. However, swap partitions can be given persistent names via mkswap.

Assigning Persistent Names to Swap Partitions

First, make quite sure you've correctly identified the swap partition (see /proc/swaps)! Then (as root) safely deactivate the current swap, reinitialise it (optionally adding a label), and reactivate it:

# swapoff /dev/sda2
# mkswap -L Swap /dev/sda2
Setting up swapspace version 1, size = 1998737 kB
LABEL=Swap, UUID=7cdfeb21-613b-4588-abb5-9d4049854e9a
# swapon /dev/sda2

You can verify the results as a normal user:

$ /sbin/blkid
/dev/sda1: LABEL=Root UUID="87f2b245-6ab3-4021-bf07-d069b4d387a1" TYPE="ext3"
/dev/sda2: LABEL=Swap UUID="7cdfeb21-613b-4588-abb5-9d4049854e9a" TYPE="swap"
/dev/sda3: LABEL=Home UUID="a6f7a63f-71ac-4361-b49a-39d62b06f18a" TYPE="ext3"
$ free
             total       used       free     shared    buffers     cached
Mem:      33017956     298700   32719256          0      17060     148668
-/+ buffers/cache:     132972   32884984
Swap:      1951888          0    1951888

Using Persistent Naming

Having chosen which naming method you'd like to use, let's now enable persistent naming for your system:

In fstab

Enabling persistent naming in /etc/fstab is easy; for each filesystem in your fstab file, just replace the device name in the first column (where it says something like /dev/sda7) with the new persistent name. This can be achieved by substituting in the appropriate path under /dev/disk, such as:

/dev/disk/by-label/home

or

/dev/disk/by-uuid/31f8eb0d-612b-4805-835e-0e6d8b8c5591

However, instead of giving an explicit /dev/disk path, the method usually recommended is to indicate how the filesystem is to be mounted by writing LABEL=<label> or UUID=<uuid> - for example:

LABEL=home

or

UUID=31f8eb0d-612b-4805-835e-0e6d8b8c5591


CategorySystemAdministration | CategoryRedundant: merge with fstab. Maybe rather with udev? at least partially? | CategoryStorage