2.2. udev device naming rules
Userspace device manager (udev) subsystem allows you to define rules for assigning persistent names to devices. These rules are stored in a file with a .rules extension.
There are two primary locations for storing the udev rules:
-
/usr/lib/udev/rules.d/directory contains default rules that come with an installed package. -
/etc/udev/rules.ddirectory is intended for customudevrules.
If a rule from /usr/lib/udev/rules.d/ is modified, it will be overwritten by the rules file of the package during an update. Hence, any manual or custom rule should be added in /etc/udev/rules.d where it is retained until removed explicitly. Before use, udev rules from both directories are merged. If a rule in /etc/udev/rules.d has the same name as one in /usr/lib/udev/rules.d/ the one in the former takes precedence.
The purpose of these rules is to ensure that storage devices are consistently and predictably identified, even across system reboots and configuration changes.
udev rules define actions to execute based on incoming events that notify about adding, changing or removing a device. This also helps to collect values for the persistent storage attributes and direct udev to create the /dev content based on the collected information. The udev rules are written in human-readable format using key-value pairs.
In the case of storage devices, udev rules control creation of symbolic links in the /dev/disk/ directory. These symbolic links provide user-friendly aliases for storage devices, making it more convenient to refer to and manage these devices.
You can create custom udev rules to specify how devices should be named based on various attributes such as serial numbers, World Wide Name (WWN) identifiers, or other device-specific characteristics. By defining specific naming rules, you have precise control over how devices are identified within the system. To create a specific custom symbolic link in /dev for a device see the udev(7) man page on your system.
While udev rules are very flexible, it is important to be aware of udev limitations:
-
Accessibility Timing: Some storage devices might not be accessible at the time of a
udevquery. -
Event-Based Processing: The kernel can send
udevevents at any time, potentially triggering rule processing and link removal if a device is inaccessible. - Processing Delay: There might be a delay between event generation and processing, especially with numerous devices, causing a lag between kernel detection and link availability.
-
Device Accessibility: External programs invoked by
udevrules, likeblkid, might briefly open the device, making it temporarily inaccessible for other tasks. -
Link Updates: Device names managed by
udevin/dev/disk/can change between major releases, requiring link updates.
The following table lists the symlinks available in /dev/disk.
| Device type | Nonpersistent Name (Kernel Name) | Persistent Symlink Names |
|---|---|---|
| Real Devices | ||
| nvme (Non-Volatile Memory Express) | /dev/nvme* | /dev/disk/by-id/nvme-<wwid> /dev/disk/by-id/nvme-<model>_<serial>_<nsid> |
| scsi (Small Computer System Interface) | /dev/sd*, /dev/sr* | /dev/disk/by-id/scsi-<model>_<serial> /dev/disk/by-id/wwn-<wwn> /dev/disk/by-id/usb-<vendor>_<model>_<serial>-<instance> /dev/disk/by-id/ieee1394-<ieee1394_id> /dev/disk/by-path/ip-<ip_address>:<ip_port>-iscsi-<iqn_name>-lun-<lun_number> /dev/disk/by-id/scsi-0<vendor>_<model>_<id> /dev/disk/by-id/scsi-1<t10_vendor_id> /dev/disk/by-id/scsi-2<eui64_id> /dev/disk/by-id/scsi-3<naa_regext_id> /dev/disk/by-id/scsi-3<naa_reg_id> /dev/disk/by-id/scsi-3<naa_ext_id> /dev/disk/by-id/scsi-3<naa_local_id> /dev/disk/by-id/scsi-8<name> /dev/disk/by-id/scsi-S<vendor>_<model>_<serial> |
| ata (Advanced Technology Attachment)/atapi (ATA Packet Interface) | /dev/sd*, /dev/sr* | /dev/disk/by-id/ata-<model>_<serial> /dev/disk/by-id/wwn-<wwn> |
| cciss (Compaq Command Interface for SCSI-3 Support) | /dev/cciss* | /dev/disk/by-id/cciss-<model>_<serial> /dev/cciss/<ccissid> |
| virtio (Virtual Input Output) | /dev/vd* | /dev/disk/by-id/virtio-<serial> |
| pmem (Persistent Memory) | /dev/pmem* | /dev/disk/by-id/pmem-<uuid> |
| mmc (MultiMedia Card) | /dev/mmcblk* | /dev/disk/by-id/mmc-<name>_<serial> |
| memstick (Memory Stick) | /dev/msblk* | /dev/disk/by-id/memstick-<name>_<serial> |
| Virtual devices | ||
| loop | /dev/loop* | /dev/disk/by-loop-inode/<id_loop_backing_device>-<id_loop_backing_inode> /dev/disk/by-loop-ref/<id_loop_backing_filename> |
| dm (device-mapper) | /dev/dm-* | /dev/mapper/<name> /dev/disk/by-id/dm-name-<name> /dev/disk/by-id/dm-uuid-<uuid> /dev/disk/by-id/wwn-<wwn> |
| md (multiple device) | /dev/md* | /dev/md/<devname> /dev/disk/by-id/md-name-<name> /dev/disk/by-id/md-uuid-<uuid> |
| Partitions (either on top of a real or a virtual device) | ||
| (any) | (any) | /dev/disk/by-partuuid/<uuid> /dev/disk/by-partlabel/<label> /dev/…/<persistent_symlink_name>-part<number> |
| LVM PVs (Logical Volume Manager Physical Volumes; either on top of a real or a virtual device) | ||
| (any) | (any) | /dev/disk/by-id/lvm-pv-uuid-<pvuuid> |
2.2.1. Obtaining the device links value for an existing device 링크 복사링크가 클립보드에 복사되었습니다!
You can obtain the value of the device links for an existing device from the current udev database.
Prerequisites
- The device is present and connected to the system.
Procedure
List all the assigned device symbolic links (
DEVLINKS) to the base kernel device node (DEVNAME) under/devfor an existing device:# udevadm info --name /dev/nvme0n1 --query property --property DEVLINKS --value /dev/disk/by-path/pci-0000:00:02.0-nvme-1 /dev/disk/by-diskseq/6 /dev/disk/by-id/nvme-QEMU_NVMe_Ctrl_nvme-1_1 /dev/disk/by-id/nvme-QEMU_NVMe_Ctrl_nvme-1 /dev/disk/by-id/nvme-QEMU_NVMe_Ctrl_nvme-1-ns-1 /dev/disk/by-id/nvme-nvme.8086-6e766d652d31-51454d55204e564d65204374726c-00000001Replace nvme0n1 with your device name.
You can also obtain the base kernel name that all the devlinks point to by using the following command:
# udevadm info --name /dev/nvme0n1 --query property --property DEVNAME --value /dev/nvme0n1The kernel name and any of its devlinks can be used interchangeably.
You can use one of the devlinks to get the full list of devlinks by using the following command:
# udevadm info --name /dev/disk/by-id/nvme-nvme.8086-6e766d652d31-51454d55204e564d65204374726c-00000001 --query property --property DEVLINKS --value /dev/disk/by-id/nvme-QEMU_NVMe_Ctrl_nvme-1 /dev/disk/by-diskseq/6 /dev/disk/by-id/nvme-nvme.8086-6e766d652d31-51454d55204e564d65204374726c-00000001 /dev/disk/by-id/nvme-QEMU_NVMe_Ctrl_nvme-1-ns-1 /dev/disk/by-id/nvme-QEMU_NVMe_Ctrl_nvme-1_1 /dev/disk/by-path/pci-0000:00:02.0-nvme-1