Difference between revisions of "Persistent block device naming"

From ArchWiki
Jump to navigation Jump to search
m (by-uuid: users can view the info just fine)
(Persistent naming methods: flag with Template:Expansion, subsections could use `blkid -o value` examples)
 
(100 intermediate revisions by 25 users not shown)
Line 2: Line 2:
 
[[Category:File systems]]
 
[[Category:File systems]]
 
[[Category:Hardware detection and troubleshooting]]
 
[[Category:Hardware detection and troubleshooting]]
 +
[[es:Persistent block device naming]]
 
[[it:Persistent block device naming]]
 
[[it:Persistent block device naming]]
[[zh-TW:UUID]]
+
[[ja:永続的なブロックデバイスの命名]]
{{Article summary start}}
+
[[ru:Persistent block device naming]]
{{Article summary text|An overview of persistent block device naming; the preferred method of referencing block devices.}}
+
[[zh-hans:Persistent block device naming]]
{{Article summary heading|Related articles}}
+
[[zh-hant:UUID]]
{{Article summary wiki|fstab}}
+
{{Related articles start}}
{{Article summary wiki|udev}}
+
{{Related|fstab}}
{{Article summary wiki|LVM}}
+
{{Related|udev}}
{{Article summary end}}
+
{{Related|LVM}}
 +
{{Related articles end}}
 +
This article describes how to use persistent names for your [[block device]]s. 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 {{ic|/dev/'''sda'''}} and {{ic|/dev/'''sdb'''}} switching around on each boot, culminating in an unbootable system, kernel panic, or a block device disappearing. Persistent naming solves these issues.
  
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 {{ic|/dev/'''sda'''}} and {{ic|/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|
{{Note|If you are using [[LVM|LVM2]], this article is not relevant as LVM takes care of this automatically.}}
+
* 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. {{Bug|42884}}) on naming it can process during boot.
 +
* This article is not relevant for [[LVM]] logical volumes as the {{ic|/dev/''VolumeGroupName''/''LogicalVolumeName''}} device paths are persistent.
 +
}}
  
==Persistent naming methods==
+
== Persistent naming methods ==
  
There are four different schemes for persistent naming: [[#by-label|by-label]], [[#by-uuid|by-uuid]], [[#by-id and by-path|by-id and by-path]]. The following sections describes what the different persistent naming methods are and how they are used.  
+
{{Expansion|Add {{ic|blkid}} commands to subsections showing how to retrieve only the UUID/LABEL/PARTUUID/PARTLABEL of a device.}}
  
Here is a good command for viewing all the information:
+
There are four different schemes for persistent naming: [[#by-label|by-label]], [[#by-uuid|by-uuid]], [[#by-id and by-path|by-id and by-path]]. For those using disks with [[GUID Partition Table|GUID Partition Table (GPT)]], two additional schemes can be used [[#by-partlabel|by-partlabel]] and [[#by-partuuid|by-partuuid]]. You can also use [[#Static device names with Udev|static device names by using Udev]].
  
{{hc|$ lsblk -f|<nowiki>
+
The directories in {{ic|/dev/disk/}} are created and destroyed dynamically, depending on whether you there are devices in them.
NAME  FSTYPE LABEL    UUID                                MOUNTPOINT
 
sda                                                       
 
├─sda1 ext2            7f4cef7e-7ee2-489a-b759-d52ba23b692c /boot
 
├─sda2 swap            a807fff3-e89f-46d0-ab17-9b7ad3efa7b5 [SWAP]
 
├─sda3 ext4            81917291-fd1a-4ffe-b95f-61c05cfba76f /
 
└─sda4 ext4            c4c23598-19fb-4562-892b-6fb18a09c7d3 /home
 
sdb
 
└─sdb1 ext4  X2      4bf265f7-da17-4575-8758-acd40885617b /mnt/X1
 
sdc
 
└─sdc1 ext4  X1      4bf265f7-da17-4575-8758-acd40885617b /mnt/X2
 
sdd
 
└─sdd1 ext4  Y2      8a976a06-3e56-476f-b73a-ea3cad41d915 /mnt/Y2
 
sde
 
└─sde1 ext4  Z2      9d35eaae-983f-4eba-abc9-434ecd4da09c /mnt/Z2
 
sdf
 
└─sdf1 ext4  Y1      e2ec37a9-0689-46a8-a07b-0609ce2b7ea2 /mnt/Y1
 
sdg
 
└─sdg1 ext4  Z1      9fa239c1-720f-42e0-8aed-39cf53a743ed /mnt/Z1
 
sdj
 
├─sdj1 ext4  RAPT    a9ed7ecb-96ce-40fe-92fa-e07a532ed157
 
└─sdj2 swap            20826c74-eb6d-46f8-84d8-69b933a4bf3f [SWAP]
 
</nowiki>}}
 
  
===by-label===
+
{{Note|Beware that [[Disk cloning]] creates two different disks with the same name.}}
  
Almost every filesystem type can have a label. All your partitions that have one are listed in the {{ic|/dev/disk/by-label}} directory. This directory is created and destroyed dynamically, depending on whether you have partitions with labels attached.
+
The following sections describes what the different persistent naming methods are and how they are used.
  
{{hc|$ ls -l /dev/disk/by-label|<nowiki>
+
The [[lsblk]] command can be used for viewing graphically the first persistent schemes:
 +
 
 +
{{hc|$ lsblk -f|
 +
NAME        FSTYPE LABEL  UUID                                MOUNTPOINT
 +
sda                                                     
 +
├─sda1      vfat          CBB6-24F2                            /boot
 +
├─sda2      ext4  System 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 {{ic|blkid}} command instead. The latter is more convenient for scripts, but more difficult to read.
 +
 
 +
{{hc|$ blkid|2=
 +
/dev/sda1: UUID="CBB6-24F2" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="d0d0d110-0a71-4ed6-936a-304969ea36af"
 +
/dev/sda2: LABEL="System" UUID="0a3407de-014b-458b-b5c1-848e92a327a3" TYPE="ext4" PARTLABEL="GNU/Linux" PARTUUID="98a81274-10f7-40db-872a-03df048df366"
 +
/dev/sda3: LABEL="Data" UUID="b411dc99-f0a0-4c87-9e05-184977be8539" TYPE="ext4" PARTLABEL="Home" PARTUUID="7280201c-fc5d-40f2-a9b2-466611d3d49e"
 +
/dev/sda4: UUID="f9fe0b69-a280-415d-a03a-a32752370dee" TYPE="swap" PARTLABEL="Swap" PARTUUID="039b6c1c-7553-4455-9537-1befbc9fbc5b"
 +
/dev/mmcblk0: PTUUID="0003e1e5" PTTYPE="dos"
 +
/dev/mmcblk0p1: UUID="F4CA-5D75" TYPE="vfat" PARTUUID="0003e1e5-01"
 +
}}
 +
 
 +
=== by-label ===
 +
 
 +
Almost every [[filesystem]] type can have a label. All your volumes that have one are listed in the {{ic|/dev/disk/by-label}} directory.
 +
 
 +
{{hc|$ ls -l /dev/disk/by-label|
 
total 0
 
total 0
lrwxrwxrwx 1 root root 10 Oct 16 10:27 data -> ../../sdb2
+
lrwxrwxrwx 1 root root 10 May 27 23:31 Data -> ../../sda3
lrwxrwxrwx 1 root root 10 Oct 16 10:27 data2 -> ../../sda2
+
lrwxrwxrwx 1 root root 10 May 27 23:31 System -> ../../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
+
Most file systems support setting the label upon file system creation, see the [[man page]] of the relevant {{ic|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:
lrwxrwxrwx 1 root root 10 Oct 16 10:27 swap -> ../../sda5
+
 
lrwxrwxrwx 1 root root 10 Oct 16 10:27 windows -> ../../sdb1
+
; swap : {{ic|swaplabel -L "''new label''" /dev/''XXX''}} using {{pkg|util-linux}}
</nowiki>}}
+
; ext2/3/4 : {{ic|e2label /dev/''XXX'' "''new label''"}} using {{pkg|e2fsprogs}}
 +
; btrfs : {{ic|btrfs filesystem label /dev/''XXX'' "''new label''"}} using {{pkg|btrfs-progs}}
 +
; reiserfs : {{ic|reiserfstune -l "''new label''" /dev/''XXX''}} using {{pkg|reiserfsprogs}}
 +
; jfs : {{ic|jfs_tune -L "''new label''" /dev/''XXX''}} using {{pkg|jfsutils}}
 +
; xfs : {{ic|xfs_admin -L "''new label''" /dev/''XXX''}} using {{pkg|xfsprogs}}
 +
; fat/vfat : {{ic|fatlabel /dev/''XXX'' "''new label''"}} using {{pkg|dosfstools}}
 +
: {{ic|mlabel -i /dev/''XXX'' ::"''new label''"}} using {{pkg|mtools}}
 +
; exfat : {{ic|exfatlabel /dev/''XXX'' "''new label''"}} using {{Pkg|exfat-utils}}
 +
; ntfs : {{ic|ntfslabel /dev/''XXX'' "''new label''"}} using {{pkg|ntfs-3g}}
 +
; udf : {{ic|udflabel /dev/''XXX'' "''new label''"}} using {{Pkg|udftools}}
 +
; crypto_LUKS (LUKS2 only) : {{ic|1=cryptsetup config --label="''new label''" /dev/''XXX''}} using {{Pkg|cryptsetup}}
  
The labels of your filesystems can be changed, but note that they have to be unambiguous to prevent any possible conflicts. Following are some methods for changing labels on common filesystems:
+
{{Note|
 +
* The file system must not be mounted to change its label. For the root file system this can be accomplished by booting from another volume.
 +
* Labels have to be unambiguous to prevent any possible conflicts.
 +
* Labels can be up to 16 characters long.
 +
* Since the label is a property of the filesystem, it is not suitable for addressing a single RAID device persistently.
 +
* When using encrypted containers with [[dm-crypt]], the labels of filesystems inside of containers are not available while the container is locked/encrypted.
 +
}}
  
; swap : {{ic|swaplabel -L <label> /dev/XXX}} using {{pkg|util-linux}}
+
=== by-uuid ===
; ext2/3/4 : {{ic|e2label /dev/XXX <label>}} using {{pkg|e2fsprogs}}
 
; btrfs : {{ic|btrfs filesystem label /dev/XXX <label>}} using {{pkg|btrfs-progs}}
 
; reiserfs : {{ic|reiserfstune -l <label> /dev/XXX}} using {{pkg|reiserfsprogs}}
 
; jfs : {{ic|jfs_tune -L <label> /dev/XXX}} using {{pkg|jfsutils}}
 
; xfs : {{ic|xfs_admin -L <label> /dev/XXX}} using {{pkg|xfsprogs}}
 
; fat/vfat : {{ic|dosfslabel /dev/XXX <label>}} using {{pkg|dosfstools}}
 
; fat/vfat : {{ic|mlabel -i /dev/XXX ::<label>}} using {{pkg|mtools}}
 
; ntfs : {{ic|ntfslabel /dev/XXX <label>}} using {{pkg|ntfs-3g}}
 
  
{{Note|Labels can be up to 16 characters long.}}
+
[[wikipedia:UUID|UUID]] is a mechanism to give each [[filesystem]] a unique identifier. These identifiers are generated by filesystem utilities (e.g. {{ic|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 {{ic|/dev/disk/by-uuid/}} with a shorter UID (unique identifier):
  
===by-uuid===
+
{{hc|$ ls -l /dev/disk/by-uuid/|
 +
total 0
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 0a3407de-014b-458b-b5c1-848e92a327a3 -> ../../sda2
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 b411dc99-f0a0-4c87-9e05-184977be8539 -> ../../sda3
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 CBB6-24F2 -> ../../sda1
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 f9fe0b69-a280-415d-a03a-a32752370dee -> ../../sda4
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 F4CA-5D75 -> ../../mmcblk0p1
 +
}}
  
[http://en.wikipedia.org/wiki/UUID UUID] is a mechanism to give each filesystem a unique identifier. It is designed so that collisions are unlikely. All GNU/Linux filesystems (including swap and LUKS headers of raw encrypted devices) support UUID. FAT and NTFS filesystems (''fat'' and ''windows'' labels above) do not support UUID, but are still listed in {{ic|/dev/disk/by-uuid}} with a shorter UID (unique identifier):
+
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).
  
{{hc|$ ls -l /dev/disk/by-uuid/|total 0
+
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.
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}}
 
  
The advantage about using the UUID method is that it is less likely that you have name collisions than with labels. 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 partition is resized or reformatted a new UUID is generated and configs have to get adjusted (manually).
+
{{Tip|In case your swap does not have an UUID assigned, you will need to reset it using the [[Swap#Swap partition|mkswap]] utility.}}
  
===by-id and by-path===
+
=== by-id and by-path ===
  
{{ic|by-id}} creates a unique name depending on the hardware serial number, {{ic|by-path}} depending on the shortest physical path (according to sysfs). Both contain strings to indicate which subsystem they belong to (i.e. {{ic|-ide-}} for {{ic|by-path}}, and {{ic|-ata-}} for {{ic|by-id}}) and thus are not suitable for solving the problems mentioned in the beginning of this article. They will not be discussed any further here.
+
{{ic|by-id}} creates a unique name depending on the hardware serial number, {{ic|by-path}} depending on the shortest physical path (according to sysfs). Both contain strings to indicate which subsystem they belong to (i.e. {{ic|pci-}} for {{ic|by-path}}, and {{ic|ata-}} for {{ic|by-id}}), so they are linked to the hardware controlling the device. This implies different levels of persistence: the {{ic|by-path}} will already change when the device is plugged into a different port of the controller, the {{ic|by-id}} will change when the device is plugged into a port of a hardware controller subject to another subsystem. [https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/5/html/Online_Storage_Reconfiguration_Guide/persistent_naming.html] Thus, both are not suitable to achieve persistent naming tolerant to hardware changes.  
  
===Individual device names===
+
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 ({{ic|by-label}} or {{ic|by-partlabel}}) and keep a directory with hardware port usage, {{ic|by-id}} and {{ic|by-path}} can be used to find a particular device.[http://linuxshellaccount.blogspot.in/2008/09/how-to-easily-find-wwns-of-qlogic-hba.html] [http://www.linuxquestions.org/questions/linux-server-73/how-to-find-wwn-for-dev-sdc-917269/]
You can also create individual device names: [[Udev#Setting static device names]].
+
 
 +
{{ic|by-id}} also creates [[Wikipedia:World Wide Name|World Wide Name]] links of storage devices that support it. Unlike other {{ic|by-id}} links, WWNs are fully persistent and will not change depending on the used subsystem.
 +
 
 +
{{hc|$ ls -l /dev/disk/by-id/|
 +
total 0
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 ata-WDC_WD2500BEVT-22ZCT0_WD-WXE908VF0470 -> ../../sda
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 ata-WDC_WD2500BEVT-22ZCT0_WD-WXE908VF0470-part1 -> ../../sda1
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 ata-WDC_WD2500BEVT-22ZCT0_WD-WXE908VF0470-part2 -> ../../sda2
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 ata-WDC_WD2500BEVT-22ZCT0_WD-WXE908VF0470-part3 -> ../../sda3
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 ata-WDC_WD2500BEVT-22ZCT0_WD-WXE908VF0470-part4 -> ../../sda4
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 mmc-SD32G_0x0040006d -> ../../mmcblk0
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 mmc-SD32G_0x0040006d-part1 -> ../../mmcblk0p1
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 wwn-0x60015ee0000b237f -> ../../sda
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 wwn-0x60015ee0000b237f-part1 -> ../../sda1
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 wwn-0x60015ee0000b237f-part2 -> ../../sda2
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 wwn-0x60015ee0000b237f-part3 -> ../../sda3
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 wwn-0x60015ee0000b237f-part4 -> ../../sda4
 +
}}
 +
 
 +
{{hc|$ ls -l /dev/disk/by-path/|
 +
total 0
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:00:1f.2-ata-1 -> ../../sda
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:00:1f.2-ata-1-part1 -> ../../sda1
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:00:1f.2-ata-1-part2 -> ../../sda2
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:00:1f.2-ata-1-part3 -> ../../sda3
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:00:1f.2-ata-1-part4 -> ../../sda4
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:07:00.0-platform-rtsx_pci_sdmmc.0 -> ../../mmcblk0
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:07:00.0-platform-rtsx_pci_sdmmc.0-part1 -> ../../mmcblk0p1
 +
}}
 +
 
 +
=== by-partlabel ===
 +
 
 +
{{Note|This method only concerns disks with [[GUID Partition Table|GUID Partition Table (GPT)]].}}
 +
 
 +
GPT partition labels can be defined in the header of the [[Wikipedia:GUID Partition Table#Partition entries (LBA 2–33)|partition entry]] on GPT disks.
 +
 
 +
This method is very similar to the [[#by-label|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 {{ic|/dev/disk/by-partlabel}} directory.
 +
 
 +
{{hc|ls -l /dev/disk/by-partlabel/|
 +
total 0
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 EFI\x20system\x20partition -> ../../sda1
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 GNU\x2fLinux -> ../../sda2
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 Home -> ../../sda3
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 Swap -> ../../sda4
 +
}}
 +
 
 +
{{Note|
 +
* GPT partition labels also have to be different to avoid conflicts. To change your partition label, you can use [[gdisk]] or the ncurses-based version [[cgdisk]]. Both are available from the {{Pkg|gptfdisk}} package. See [[Partitioning#Partitioning tools]].
 +
* According to the specification, GPT partition labels can be up to 72 characters long.
 +
}}
 +
 
 +
=== by-partuuid ===
 +
 
 +
Like [[#by-partlabel|GPT partition labels]], GPT partition UUIDs are defined in the [[Wikipedia:GUID Partition Table#Partition entries (LBA 2–33)|partition entry]] on GPT disks.
 +
 
 +
MBR does not support partition UUIDs, but Linux[https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=d33b98fc82b0908e91fb05ae081acaed7323f9d2] and software using libblkid[https://git.kernel.org/pub/scm/utils/util-linux/util-linux.git/commit/?id=d67cc2889a0527b26d7bb8c76f2acac46751d673] (e.g. udev[https://github.com/systemd/systemd/pull/3293]) are capable of generating pseudo PARTUUIDs for MBR partitions. The format is {{ic|''SSSSSSSS''-''PP''}}, where {{ic|''SSSSSSSS''}} is a zero-filled 32-bit [[Wikipedia:Master boot record#Disk identity|MBR disk signature]], and {{ic|''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 [[#by-uuid|filesystem UUIDs]], using UUIDs is preferred over labels.
 +
 
 +
{{hc|ls -l /dev/disk/by-partuuid/|
 +
total 0
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 0003e1e5-01 -> ../../mmcblk0p1
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 039b6c1c-7553-4455-9537-1befbc9fbc5b -> ../../sda4
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 7280201c-fc5d-40f2-a9b2-466611d3d49e -> ../../sda3
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 98a81274-10f7-40db-872a-03df048df366 -> ../../sda2
 +
lrwxrwxrwx 1 root root 10 May 27 23:31 d0d0d110-0a71-4ed6-936a-304969ea36af -> ../../sda1
 +
}}
 +
 
 +
=== Static device names with Udev ===
 +
 
 +
See [[udev#Setting static device names]].
  
 
==Using persistent naming==
 
==Using persistent naming==
Line 100: Line 191:
 
There are various applications that can be configured using persistent naming. Following are some examples of how to configure them.
 
There are various applications that can be configured using persistent naming. Following are some examples of how to configure them.
  
===[[fstab]]===
+
=== fstab ===
  
To enable persistent naming in {{ic|/etc/fstab}} replace the device kernel name in the first column with the persistent name path as follows:
+
See the main article: [[fstab#Identifying filesystems]].
  
/dev/disk/by-label/home_myhost ...
+
=== Boot managers ===
/dev/disk/by-uuid/31f8eb0d-612b-4805-835e-0e6d8b8c5591 [...]
 
  
or directly specify the persistent name type using a prefix:
+
To use persistent names in the [[Boot loader|boot manager (boot loader)]], the following prerequisites must be met. On a standard installation following the installation guide both prerequisites are met.
  
LABEL=home_myhost ...
+
* You are using a [[mkinitcpio#Configuration|mkinitcpio]] initial RAM disk image
UUID=1f8eb0d-612b-4805-835e-0e6d8b8c5591 [...]
+
* You have udev enabled in {{ic|/etc/mkinitcpio.conf}}
 
 
===Boot managers===
 
  
To use persistent names in your boot manager, the following prerequisites must be met:
+
The location of the root filesystem is given by the parameter {{ic|root}} on the kernel commandline. The kernel commandline is configured from the bootloader, see [[Kernel parameters#Configuration]]. To change to persistent device naming, only change the parameters which specify block devices, e.g. {{ic|root}} and {{ic|resume}}, while leaving other parameters as is. Various naming schemes are supported:
  
* You are using a [[Mkinitcpio#Configuration|mkinitcpio]] initial RAM disk image
+
Persistent device naming using label and the {{ic|1=LABEL=}} format, in this example {{ic|System}} is the LABEL of the root file system.
* You have udev enabled in {{ic|/etc/mkinitcpio.conf}}
 
  
In the above example, {{ic|/dev/sda1}} is the root partition. In the [[GRUB]] {{ic|grub.cfg}} file, the ''linux'' line looks like this:
+
root=LABEL=System
  
linux /boot/vmlinuz-linux root=/dev/sda1 ro quiet
+
Persistent device naming using UUID and the {{ic|1=UUID=}} format, in this example {{ic|0a3407de-014b-458b-b5c1-848e92a327a3}} is the UUID of the root file system.
  
Depending on which naming scheme you would prefer, change it to one of the following:
+
root=UUID=0a3407de-014b-458b-b5c1-848e92a327a3
  
linux /boot/vmlinuz-linux root=/dev/disk/by-label/root_myhost ro quiet
+
Persistent device naming using disk id and the {{ic|/dev}} path format, in this example {{ic|wwn-0x60015ee0000b237f-part2}} is the id of the root partition.
  
or:
+
root=/dev/disk/by-id/wwn-0x60015ee0000b237f-part2
  
linux /boot/vmlinuz-linux root=UUID=2d781b26-0285-421a-b9d0-d4a0d3b55680 ro quiet
+
Persistent device naming using GPT partition UUID and the {{ic|1=PARTUUID=}} format, in this example {{ic|98a81274-10f7-40db-872a-03df048df366}} is the PARTUUID of the root partition.
  
If you are using [[LILO]], then do not try this with the {{ic|1=root=...}} configuration option; it will not work. Use {{ic|1=append="root=..."}} or {{ic|1=addappend="root=..."}} instead. Read the LILO man page for more information on {{ic|append}} and {{ic|addappend}}.
+
root=PARTUUID=98a81274-10f7-40db-872a-03df048df366
  
There is an alternative way to use the label embedded in the filesystem. For example if (as above) the filesystem in {{ic|/dev/sda1}} is labeled {{ic|root_myhost}}, you would give this line to GRUB:
+
Persistent device naming using GPT partition label and the {{ic|1=PARTLABEL=}} format, in this example {{ic|GNU/Linux}} is the PARTLABEL of the root partition.
  
  linux /boot/vmlinuz-linux root=LABEL=root_myhost ro quiet
+
  root="PARTLABEL=GNU/Linux"

Latest revision as of 14:59, 16 March 2019

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

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Add blkid commands to subsections showing how to retrieve only the UUID/LABEL/PARTUUID/PARTLABEL of a device. (Discuss in Talk:Persistent block device naming#)

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 you there are devices in them.

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

The following sections describes 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   System 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 blkid command instead. The latter is more convenient for scripts, but more difficult to read.

$ blkid
/dev/sda1: UUID="CBB6-24F2" TYPE="vfat" PARTLABEL="EFI system partition" PARTUUID="d0d0d110-0a71-4ed6-936a-304969ea36af" 
/dev/sda2: LABEL="System" UUID="0a3407de-014b-458b-b5c1-848e92a327a3" TYPE="ext4" PARTLABEL="GNU/Linux" PARTUUID="98a81274-10f7-40db-872a-03df048df366" 
/dev/sda3: LABEL="Data" UUID="b411dc99-f0a0-4c87-9e05-184977be8539" TYPE="ext4" PARTLABEL="Home" PARTUUID="7280201c-fc5d-40f2-a9b2-466611d3d49e" 
/dev/sda4: UUID="f9fe0b69-a280-415d-a03a-a32752370dee" TYPE="swap" PARTLABEL="Swap" PARTUUID="039b6c1c-7553-4455-9537-1befbc9fbc5b"
/dev/mmcblk0: PTUUID="0003e1e5" PTTYPE="dos"
/dev/mmcblk0p1: UUID="F4CA-5D75" TYPE="vfat" PARTUUID="0003e1e5-01"

by-label

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

$ ls -l /dev/disk/by-label
total 0
lrwxrwxrwx 1 root root 10 May 27 23:31 Data -> ../../sda3
lrwxrwxrwx 1 root root 10 May 27 23:31 System -> ../../sda2

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 util-linux
ext2/3/4 
e2label /dev/XXX "new label" using e2fsprogs
btrfs 
btrfs filesystem label /dev/XXX "new label" using btrfs-progs
reiserfs 
reiserfstune -l "new label" /dev/XXX using reiserfsprogs
jfs 
jfs_tune -L "new label" /dev/XXX using jfsutils
xfs 
xfs_admin -L "new label" /dev/XXX using xfsprogs
fat/vfat 
fatlabel /dev/XXX "new label" using dosfstools
mlabel -i /dev/XXX ::"new label" using mtools
exfat 
exfatlabel /dev/XXX "new label" using exfat-utils
ntfs 
ntfslabel /dev/XXX "new label" using ntfs-3g
udf 
udflabel /dev/XXX "new label" using udftools
crypto_LUKS (LUKS2 only) 
cryptsetup config --label="new label" /dev/XXX using cryptsetup
Note:
  • The file system must not be mounted to change its label. For the root file system this can be accomplished by booting from another volume.
  • Labels have to be unambiguous to prevent any possible conflicts.
  • Labels can be up to 16 characters long.
  • Since the label is a property of the filesystem, it is not suitable for addressing a single RAID device persistently.
  • When using encrypted containers with dm-crypt, the labels of filesystems inside of containers are not available while the container is locked/encrypted.

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 /dev/disk/by-uuid/ with a shorter UID (unique identifier):

$ ls -l /dev/disk/by-uuid/
total 0
lrwxrwxrwx 1 root root 10 May 27 23:31 0a3407de-014b-458b-b5c1-848e92a327a3 -> ../../sda2
lrwxrwxrwx 1 root root 10 May 27 23:31 b411dc99-f0a0-4c87-9e05-184977be8539 -> ../../sda3
lrwxrwxrwx 1 root root 10 May 27 23:31 CBB6-24F2 -> ../../sda1
lrwxrwxrwx 1 root root 10 May 27 23:31 f9fe0b69-a280-415d-a03a-a32752370dee -> ../../sda4
lrwxrwxrwx 1 root root 10 May 27 23:31 F4CA-5D75 -> ../../mmcblk0p1

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.

Tip: In case your swap does not have an UUID assigned, you will need to reset it using the mkswap utility.

by-id and by-path

by-id 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. pci- for by-path, and ata- for by-id), 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 by-id will change when the device is plugged into a port of a hardware controller subject to another subsystem. [1] 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 (by-label or by-partlabel) and keep a directory with hardware port usage, by-id and by-path can be used to find a particular device.[2] [3]

by-id also creates World Wide Name links of storage devices that support it. Unlike other by-id links, WWNs are fully persistent and will not change depending on the used subsystem.

$ ls -l /dev/disk/by-id/
total 0
lrwxrwxrwx 1 root root 10 May 27 23:31 ata-WDC_WD2500BEVT-22ZCT0_WD-WXE908VF0470 -> ../../sda
lrwxrwxrwx 1 root root 10 May 27 23:31 ata-WDC_WD2500BEVT-22ZCT0_WD-WXE908VF0470-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 May 27 23:31 ata-WDC_WD2500BEVT-22ZCT0_WD-WXE908VF0470-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 May 27 23:31 ata-WDC_WD2500BEVT-22ZCT0_WD-WXE908VF0470-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 May 27 23:31 ata-WDC_WD2500BEVT-22ZCT0_WD-WXE908VF0470-part4 -> ../../sda4
lrwxrwxrwx 1 root root 10 May 27 23:31 mmc-SD32G_0x0040006d -> ../../mmcblk0
lrwxrwxrwx 1 root root 10 May 27 23:31 mmc-SD32G_0x0040006d-part1 -> ../../mmcblk0p1
lrwxrwxrwx 1 root root 10 May 27 23:31 wwn-0x60015ee0000b237f -> ../../sda
lrwxrwxrwx 1 root root 10 May 27 23:31 wwn-0x60015ee0000b237f-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 May 27 23:31 wwn-0x60015ee0000b237f-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 May 27 23:31 wwn-0x60015ee0000b237f-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 May 27 23:31 wwn-0x60015ee0000b237f-part4 -> ../../sda4
$ ls -l /dev/disk/by-path/
total 0
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:00:1f.2-ata-1 -> ../../sda
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:00:1f.2-ata-1-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:00:1f.2-ata-1-part2 -> ../../sda2
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:00:1f.2-ata-1-part3 -> ../../sda3
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:00:1f.2-ata-1-part4 -> ../../sda4
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:07:00.0-platform-rtsx_pci_sdmmc.0 -> ../../mmcblk0
lrwxrwxrwx 1 root root 10 May 27 23:31 pci-0000:07:00.0-platform-rtsx_pci_sdmmc.0-part1 -> ../../mmcblk0p1

by-partlabel

Note: This method only concerns disks with GUID Partition Table (GPT).

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 /dev/disk/by-partlabel directory.

ls -l /dev/disk/by-partlabel/
total 0
lrwxrwxrwx 1 root root 10 May 27 23:31 EFI\x20system\x20partition -> ../../sda1
lrwxrwxrwx 1 root root 10 May 27 23:31 GNU\x2fLinux -> ../../sda2
lrwxrwxrwx 1 root root 10 May 27 23:31 Home -> ../../sda3
lrwxrwxrwx 1 root root 10 May 27 23:31 Swap -> ../../sda4
Note:
  • GPT partition labels also have to be different to avoid conflicts. To change your partition label, you can use gdisk or the ncurses-based version cgdisk. Both are available from the gptfdisk package. See Partitioning#Partitioning tools.
  • According to the specification, GPT partition labels can be up to 72 characters long.

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[4] and software using libblkid[5] (e.g. udev[6]) are capable of generating pseudo PARTUUIDs for MBR partitions. The format is SSSSSSSS-PP, where SSSSSSSS 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.

ls -l /dev/disk/by-partuuid/
total 0
lrwxrwxrwx 1 root root 10 May 27 23:31 0003e1e5-01 -> ../../mmcblk0p1
lrwxrwxrwx 1 root root 10 May 27 23:31 039b6c1c-7553-4455-9537-1befbc9fbc5b -> ../../sda4
lrwxrwxrwx 1 root root 10 May 27 23:31 7280201c-fc5d-40f2-a9b2-466611d3d49e -> ../../sda3
lrwxrwxrwx 1 root root 10 May 27 23:31 98a81274-10f7-40db-872a-03df048df366 -> ../../sda2
lrwxrwxrwx 1 root root 10 May 27 23:31 d0d0d110-0a71-4ed6-936a-304969ea36af -> ../../sda1

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 filesystems.

Boot managers

To use persistent names in the boot manager (boot loader), the following prerequisites must be met. On a standard installation following the installation guide both prerequisites are met.

  • You are using a mkinitcpio initial RAM disk image
  • You have udev enabled in /etc/mkinitcpio.conf

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

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

root=LABEL=System

Persistent device naming using UUID and the UUID= 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 /dev path format, in this example wwn-0x60015ee0000b237f-part2 is the id of the root partition.

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

Persistent device naming using GPT partition UUID and the PARTUUID= format, in this example 98a81274-10f7-40db-872a-03df048df366 is the PARTUUID of the root partition.

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

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

root="PARTLABEL=GNU/Linux"