udev rules in /etc/udev/rules.d/ ignored/not-loaded on boot; exec manually OK at shell ?

pgnd pgnd at dev-mail.net
Thu Dec 21 13:18:00 UTC 2023


i'm trying to set a systemd-networkd-managed ethernet interface's sysctls _after_ it's renamed on boot, with a udev rule.

it appears that my udev rule in /etc/udev/rules.d/ is ignored -- not loaded -- and hence fails to exec on boot.

but it execs OK @ shell after boot :-/

on


	lsb_release -rd
		Description:    Fedora release 39 (Thirty Nine)
		Release:        39
	uname -rm
		6.6.6-200.fc39.x86_64 x86_64
	rpm -qa | grep ^systemd-2
		systemd-254.7-1.fc39.x86_64

i have this ethernet device

	lspci | grep Ethernet | grep 05:00
		05:00.0 Ethernet controller: Intel Corporation I211 Gigabit Network Connection (rev 03)

i enable persistent naming; in kernel cmdline,

	... net.ifnames=1 ...

the interface is renamed/created during boot


	dmesg | grep "renamed from eth"
		[    6.945108] igb 0000:05:00.0 enp5s0: renamed from eth0

i've created a udev rule to set IPv6 params


	cat /etc/udev/rules.d/01-enp5s0-sysctl.rules
		ACTION=="add|bind|change", SUBSYSTEM=="net", KERNEL=="enp5s0", \
		 RUN+="/sbin/sysctl -qw \
		  net.ipv6.conf.enp5s0.forwarding=0 \
		  net.ipv6.conf.enp5s0.accept_ra=1 \
		  net.ipv6.conf.enp5s0.use_tempaddr=1 \
		 "

but, immediately after boot, checking

	sysctl \
	 net.ipv6.conf.enp5s0.forwarding \
	 net.ipv6.conf.enp5s0.accept_ra \
	 net.ipv6.conf.enp5s0.use_tempaddr

returns the values, unchanged,


	net.ipv6.conf.enp5s0.forwarding = 0
	net.ipv6.conf.enp5s0.accept_ra = 0
	net.ipv6.conf.enp5s0.use_tempaddr = 0

same also if filename-priority is changed, to

	/etc/udev/rules.d/99-enp5s0-sysctl.rules`

otoh, if i exec at shell,


	udevadm trigger
	sysctl \
	 net.ipv6.conf.enp5s0.forwarding \
	 net.ipv6.conf.enp5s0.accept_ra \
	 net.ipv6.conf.enp5s0.use_tempaddr

monitoring as well,

	udevadm monitor | grep enp5s0
		KERNEL[40344.410195] change   /devices/pci0000:00/0000:00:01.2/0000:01:00.0/0000:02:05.0/0000:05:00.0/net/enp5s0 (net)
		UDEV  [40344.529849] change   /devices/pci0000:00/0000:00:01.2/0000:01:00.0/0000:02:05.0/0000:05:00.0/net/enp5s0 (net)

the values are changed

	net.ipv6.conf.enp5s0.forwarding = 0
	net.ipv6.conf.enp5s0.accept_ra = 1
	net.ipv6.conf.enp5s0.use_tempaddr = 1


from linux-hotplug ML, another user commented,

	"udev doesn't seem to be reading from /etc/ude/rules.d/ anymore on the initramfs.  I'd suggest as a workaround of copying the file to usr/lib/udev/rules.d and adding that file to your mkinitcpio.conf file under FILES. That worked for me, but isn't really an ideal solution."

checking boot logs,


	journalctl -b | grep systemd-udevd  | grep /etc
		Dec 20 19:24:16 dev systemd-udevd[522]: Trying to open "/etc/systemd/hwdb/hwdb.bin"...
		Dec 20 19:24:16 dev systemd-udevd[522]: Trying to open "/etc/udev/hwdb.bin"...
		Dec 20 19:24:16 dev systemd-udevd[522]: Reading rules file: /etc/udev/rules.d/11-dm.rules
		Dec 20 19:24:16 dev systemd-udevd[522]: Reading rules file: /etc/udev/rules.d/59-persistent-storage-dm.rules
		Dec 20 19:24:16 dev systemd-udevd[522]: Reading rules file: /etc/udev/rules.d/59-persistent-storage-md.rules
		Dec 20 19:24:16 dev systemd-udevd[522]: Reading rules file: /etc/udev/rules.d/59-persistent-storage.rules
		Dec 20 19:24:16 dev systemd-udevd[522]: Reading rules file: /etc/udev/rules.d/61-persistent-storage.rules
		Dec 20 19:24:16 dev systemd-udevd[522]: Reading rules file: /etc/udev/rules.d/64-lvm.rules
		Dec 20 19:24:16 dev systemd-udevd[522]: Reading rules file: /etc/udev/rules.d/65-md-incremental-imsm.rules

my rule,

	ls -al /etc/udev/rules.d/
		-rw-r--r--  1 root root 2.2K Dec 20 18:47 99-enp5s0-sysctl.rules

is seemingly missing/ignored

the rules that ARE loaded and reported as 'in'

	/etc/udev/rules.d/

, are in-fact sourced from

	/usr/lib/dracut/modules.d,

where,

	find /usr/lib/dracut/modules.d -type f \
	 -iname 11-dm.rules \
	 -o -iname 59-persistent-storage-dm.rules \
	 -o -iname 59-persistent-storage-md.rules \
	 -o -iname 59-persistent-storage.rules \
	 -o -iname 61-persistent-storage.rules \
	 -o -iname 64-lvm.rules \
	 -o -iname 65-md-incremental-imsm.rules

		/usr/lib/dracut/modules.d/90dm/11-dm.rules
		/usr/lib/dracut/modules.d/90dm/59-persistent-storage-dm.rules
		/usr/lib/dracut/modules.d/90mdraid/59-persistent-storage-md.rules
		/usr/lib/dracut/modules.d/90mdraid/65-md-incremental-imsm.rules
		/usr/lib/dracut/modules.d/95udev-rules/59-persistent-storage.rules
		/usr/lib/dracut/modules.d/95udev-rules/61-persistent-storage.rules
		/usr/lib/dracut/modules.d/90lvm/64-lvm.rules


current udev man states,

	"The udev rules are read from the files located in the system rules directories /usr/lib/udev/rules.d and /usr/local/lib/udev/rules.d, the volatile runtime directory /run/udev/rules.d and the local administration directory /etc/udev/rules.d. All rules files are collectively sorted and processed in lexical order, regardless of the directories in which they live. However, files with identical filenames replace each other. Files in /etc/ have the highest priority, files in /run/ take precedence over files with the same name under /usr/. This can be used to override a system-supplied rules file with a local file if needed; a symlink in /etc/ with the same name as a rules file in /usr/lib/, pointing to /dev/null, disables the rules file entirely. Rule files must have the extension .rules; other extensions are ignored."

so, iiuc, 'my' rule _should_ be getting picked up.

what's keeping my udev rule from setting up the interface sysctls on boot?
a systemd/udev bug? or pebkac in my config/usage?



More information about the systemd-devel mailing list