Persistent block device naming

This article describes how to use persistent names for your block devices. This has been made possible by the introduction of udev and has some advantages over bus-based naming. If your machine has more than one SATA, SCSI or IDE disk controller, the order in which their corresponding device nodes are added is arbitrary. This may result in device names like /dev/sda and /dev/sdb switching around on each boot, culminating in an unbootable system, kernel panic, or a block device disappearing. Persistent naming solves these issues.

Note:
  • Persistent naming has limits that are out-of-scope in this article. For example, while mkinitcpio may support a method, systemd may impose its own limits (e.g. FS#42884) on naming it can process during boot.
  • This article is not relevant for LVM logical volumes as the /dev/VolumeGroupName/LogicalVolumeName device paths are persistent.

Persistent naming methods

There are four different schemes for persistent naming: by-label, by-uuid, by-id and by-path. For those using disks with GUID Partition Table (GPT), two additional schemes can be used by-partlabel and by-partuuid. You can also use static device names by using Udev.

The directories in /dev/disk/ are created and destroyed dynamically, depending on whether there are devices in them.

Note: Beware that Disk cloning creates two different disks with the same name.

The following sections describe what the different persistent naming methods are and how they are used.

The lsblk command can be used for viewing graphically the first persistent schemes:

$ lsblk -f
NAME        FSTYPE LABEL      UUID                                 MOUNTPOINT
sda                                                       
├─sda1      vfat              CBB6-24F2                            /boot
├─sda2      ext4   Arch Linux 0a3407de-014b-458b-b5c1-848e92a327a3 /
├─sda3      ext4   Data       b411dc99-f0a0-4c87-9e05-184977be8539 /home
└─sda4      swap              f9fe0b69-a280-415d-a03a-a32752370dee [SWAP]
mmcblk0
└─mmcblk0p1 vfat              F4CA-5D75

For those using GPT, use the command instead. The latter is more convenient for scripts, but more difficult to read.

by-label

Almost every file system type can have a label. All your volumes that have one are listed in the directory.

Most file systems support setting the label upon file system creation, see the man page of the relevant mkfs.* utility. For some file systems it is also possible to change the labels. Following are some methods for changing labels on common file systems:

swap 
swaplabel -L "new label" /dev/XXX using
ext2/3/4 
using
btrfs 
using
reiserfs 
using
jfs 
using jfsutils
xfs 
xfs_admin -L "new label" /dev/XXX using
fat/vfat 
using
using
exfat 
using
using or
ntfs 
ntfslabel /dev/XXX "new label" using
udf 
udflabel /dev/XXX "new label" using
crypto_LUKS (LUKS2 only) 
using

The label of a device can be obtained with lsblk:

Or with blkid:

by-uuid

UUID is a mechanism to give each filesystem a unique identifier. These identifiers are generated by filesystem utilities (e.g. mkfs.*) when the device gets formatted and are designed so that collisions are unlikely. All GNU/Linux filesystems (including swap and LUKS headers of raw encrypted devices) support UUID. FAT, exFAT and NTFS filesystems do not support UUID, but are still listed in with a shorter UID (unique identifier):

The UUID of a device can be obtained with lsblk:

$ lsblk -dno UUID /dev/sda1
CBB6-24F2

Or with blkid:

The advantage of using the UUID method is that it is much less likely that name collisions occur than with labels. Further, it is generated automatically on creation of the filesystem. It will, for example, stay unique even if the device is plugged into another system (which may perhaps have a device with the same label).

The disadvantage is that UUIDs make long code lines hard to read and break formatting in many configuration files (e.g. fstab or crypttab). Also every time a volume is reformatted a new UUID is generated and configuration files have to get manually adjusted.

by-id and by-path

creates a unique name depending on the hardware serial number, by-path depending on the shortest physical path (according to sysfs). Both contain strings to indicate which subsystem they belong to (i.e.  for by-path, and  for ), so they are linked to the hardware controlling the device. This implies different levels of persistence: the by-path will already change when the device is plugged into a different port of the controller, the  will change when the device is plugged into a port of a hardware controller subject to another subsystem.  Thus, both are not suitable to achieve persistent naming tolerant to hardware changes. 

However, both provide important information to find a particular device in a large hardware infrastructure. For example, if you do not manually assign persistent labels ( or ) and keep a directory with hardware port usage, and by-path can be used to find a particular device.

also creates World Wide Name links of storage devices that support it. Unlike other  links, WWNs are fully persistent and will not change depending on the used subsystem.
Note: by-id and by-path links can only be considered persistent for disks, not partitions. Partitions will be referenced by their number in the partition table and that can change if the partitions are reordered.

by-partlabel

GPT partition labels can be defined in the header of the partition entry on GPT disks.

This method is very similar to the filesystem labels, except the partition labels do not get affected if the file system on the partition is changed.

All partitions that have partition labels are listed in the directory.

The partition label of a device can be obtained with lsblk:

Or with blkid:

# blkid -s PARTLABEL -o value /dev/sda1
EFI system partition

by-partuuid

Like GPT partition labels, GPT partition UUIDs are defined in the partition entry on GPT disks.

MBR does not support partition UUIDs, but Linux and software using libblkid (e.g. udev) are capable of generating pseudo PARTUUIDs for MBR partitions. The format is , where is a zero-filled 32-bit MBR disk signature, and PP is a zero-filled partition number in hexadecimal form. Unlike a regular PARTUUID of a GPT partition, MBR's pseudo PARTUUID can change if the partition number changes.

The dynamic directory is similar to other methods and, like filesystem UUIDs, using UUIDs is preferred over labels.

The partition UUID of a device can be obtained with lsblk:

Or with blkid:

Static device names with udev

See udev#Setting static device names.

Using persistent naming

There are various applications that can be configured using persistent naming. Following are some examples of how to configure them.

fstab

See the main article: fstab#Identifying file systems.

Kernel parameters

To use persistent names in kernel parameters, the following prerequisites must be met. On a standard installation following the installation guide both prerequisites are met:

The location of the root filesystem is given by the parameter on the kernel command line. The kernel command line is configured from the boot loader, see Kernel parameters#Configuration. To change to persistent device naming, only change the parameters which specify block devices, e.g. and resume, while leaving other parameters as is. Various naming schemes are supported:

Persistent device naming using label and the format, in this example is the LABEL of the root file system.

root="LABEL=Arch Linux"

Persistent device naming using UUID and the format, in this example 0a3407de-014b-458b-b5c1-848e92a327a3 is the UUID of the root file system.

root=UUID=0a3407de-014b-458b-b5c1-848e92a327a3

Persistent device naming using disk id and the path format, in this example is the id of the root partition.

root=/dev/disk/by-id/wwn-0x60015ee0000b237f-part2

Persistent device naming using GPT partition UUID and the format, in this example is the PARTUUID of the root partition.

root=PARTUUID=98a81274-10f7-40db-872a-03df048df366

Persistent device naming using GPT partition label and the format, in this example GNU/Linux is the PARTLABEL of the root partition.

root="PARTLABEL=GNU/Linux"
gollark: Which at least run on a long annoying calendar.
gollark: And lunar heralds.
gollark: Perhaps add a sinomorph.
gollark: April Fools' idea: do a serious feature update.
gollark: Perhaps.
This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.