udev matching does not work
This document (3235532) is provided subject to the disclaimer at the end of this document.
Environment
SUSE Linux Enterprise Server 10
Situation
Multiple iSCSI-based devices are connected to the host and since the order of the connection establishment to each of the targets their /dev/sd? assignment may vary, eg. /dev/sdb is not always linked the same iSCSI target.
Goal
We want to create rules that set up a symlink based on e.g.only a part of the iSCSI target name to avoid awfully long entries in /etc/fstab, which must be updated if the iSCSI target is being renamed/recreated/moved.
To achieve this the following rules are constructed :
# Match on *ivol1* in ID_PATH and log to syslog KERNEL=="sd*[!0-9]", ENV{ID_VENDOR}=="IET", ENV{ID_PATH}=="*ivol1*", RUN+="/bin/logger Creating symlink /dev/disk/iscsi/ivol1 for $env{ID_PATH}", SYMLINK+="disk/iscsi/ivol1" # Match on *ivol2* in ID_PATH and log to syslog KERNEL=="sd*[!0-9]", ENV{ID_VENDOR}=="IET", ENV{ID_PATH}=="*ivol2*", RUN+="/bin/logger Creating symlink /dev/disk/iscsi/ivol2 for $env{ID_PATH}", SYMLINK+="disk/iscsi/ivol2"These will persistently enable us to eg. mount an iSCSI target that has the string "ivol1” in its name from/dev/disk/iscsi/ivol1 so that the entry in /etc/fstab could look like
Symptom
The match on ENV{ID_PATH}=="*whatever*" does not work at all.
It is possible to display the contents of certain udev environment variables in a udev rule in/etc/udev/rules.d/60-persistent-storage.rules, but at the same time it is not possible to perform a match on them.
While it is possible to match onENV{ID_VENDOR}, matches on eg. ENV{ID_PATH} or ENV{ID_FS_UUID} do not work.
What might be even more confusing is that the variables really seem to be populated if tested with a rule like this, which will display its output in syslog :
KERNEL=="sd*", ENV{ID_VENDOR}=="IET", RUN+="/bin/logger ID_VENDOR contains $env{ID_VENDOR} , ID_FS_UUID contains $env{ID_FS_UUID} and ID_PATH is $env{ID_PATH}"
Resolution
The root cause is incorrect order of rules.
The reason for this to fail is usually that the rule is executed before the calls to path_id and vol_id in /etc/udev/rules.d/60-persistent-storage.rules. The confusion about that you are able to display the contents of the variables in the RUN key, is that RUN keys are "postprocess" instructions which will be evaluated _after_ all rules are run, so they work in the debugging rule, while the variables are not yet initialized at the time the SYMLINK assignment key is executed.
Resolution
Since the rule files in/etc/udev/rules.d/are executed in alphabetical order, the simplest solution is to move the rules out of /etc/udev/rules.d/60-persistent-storage.rules and create a new file, which is executed later, e.g. by naming it61-persistent-iscsi.rules.
Alternatively the rules can be moved to the bottom of 60-persistent-storage.rules - just above the last line containing "LABEL="persistent_storage_end"".
Disclaimer
This Support Knowledgebase provides a valuable tool for SUSE customers and parties interested in our products and solutions to acquire information, ideas and learn from one another. Materials are provided for informational, personal or non-commercial use within your organization and are presented "AS IS" WITHOUT WARRANTY OF ANY KIND.
- Document ID:3235532
- Creation Date: 15-Jan-2008
- Modified Date:04-Mar-2021
-
- SUSE Linux Enterprise Desktop
- SUSE Linux Enterprise Server
For questions or concerns with the SUSE Knowledgebase please contact: tidfeedback[at]suse.com