How to make block device NVMe assigned names persistent?
Environment
- Red Hat Enterprise Linux 7, 8, 9 and 10
- NVMe storage (Non-Volatile Memory express)
Issue
- How to write udev rule to create persistent name of NVMe devices?
- udev rule for NVMe devices
Resolution
-
Get the ID_SERIAL_SHORT of nvme device.
$ udevadm info --query=all --path=/block/nvme1n1 | grep ID_SERIAL_SHORT E: ID_SERIAL_SHORT=S4FVBS0M4652 -
Create udev rule file in directory
/etc/udev/rules.d/and may give some illustrative name like99-nvmepersistent.rules -
Add the below entry in rule file.
KERNEL=="nvme*[0-9]n*[0-9]", SUBSYSTEM=="block", ENV{DEVTYPE}=="disk", ENV{ID_SERIAL_SHORT}=="S4FVBS0M4652", SYMLINK+="NAME1" -
Reload and trigger udev rules using below commands.
$ /sbin/udevadm control --reload-rules $ /sbin/udevadm trigger --type=devices --action=change -
Because of the udev rule, a symlink named "NAME1" linking to the nvme device will be created. Even if the name of the nvme device changes, the symlink links to the same nvme device persistently.
$ ls -l /dev/NAME1 $ lrwxrwxrwx. 1 root root 7 Feb 16 09:57 /dev/NAME1 -> nvme1n1
SBR
Product(s)
Components
Category
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.