3

Alongside an RPM package, I have been preparing a DEB package for some software which requires the installation of some udev rules.

My RPM package installs the rules in /usr/lib/udev/rules.d. My understanding is that /usr/lib/udev/rules.d is where the rules of third-party (non-distro) packages are supposed to reside.

I've tested the RPM package on Fedora 35 - all good. The rules are applied when the relevant udev events are triggered.

My DEB package currently installs the same rules in the same place, but when testing the DEB package on a fresh install of Ubuntu 18.04, the installed rules are not being applied (when I trigger the relevant udev events). I was able to get it working by moving the rules to /etc/udev/rules.d. This makes me suspect that rules in /usr/lib/udev/rules.d are not loaded, on Debian-based systems.

After a little research, all of the documentation I've found (RE udev rules on Debian) claims that Debian expects the rule files to be placed in /lib/udev/rules.d:

The rules files (which amount to more configuration for udevd) are taken from /run/udev/rules.d, /etc/udev/rules.d or /lib/udev/rules.d. Packages install rules in /lib/udev/rules.d), while the /etc and /run locations provide a facility for the administrator to override the behavior of a package-provided rule.

Source

I was under the impression that the /lib directory was for packages that are considered to be essential to the system. From the FHS:

The /lib directory contains those shared library images needed to boot the system and run the commands in the root filesystem, ie. by binaries in /bin and /sbin.

Source

Where am I to put these udev rules? My package is certainly not considered to be essential to the system. If I put them in /lib, isn't that going against the FHS? And finally, should the location really differ across distros? Why can't I just put them in one place, across all Linux distros?

Edit:

I've just realised that, since Ubuntu 20.04, /lib is symlinked to /usr/lib, so the location of the udev rules will probably be less of a problem on those systems, but I'd still like to know where I should put them, on Ubuntu 18.04 systems.

6
  • /etc/udev/rules.d is the right location from what I've seen. Jan 18, 2023 at 20:35
  • 1
    @ArtemS.Tashkinov I used to install them in /etc/udev/rules.d, but recently learned that it's only for overrides - packages shouldn't install udev rules in there. It's for admins to manually override default rules. At least that's how I understand it.
    – navnav
    Jan 18, 2023 at 20:37
  • This is not what man udev says: 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. Jan 19, 2023 at 8:49
  • The /usr directory (except /usr/local) has always been for distro files only. Jan 19, 2023 at 8:53
  • @Artem I tend to consider the rule to be that /usr (except /usr/local, as you say) is for files managed by the distro’s package manager only (because that’s what really matters) — administrators using their own packages are effectively working on a forked distro anyway, and should follow the distro packaging rules, including packaging files in /usr, /lib etc. as appropriate. They don’t risk overwriting distro files or having their own files overwritten by the distro if their files are managed by the package manager. Jan 19, 2023 at 9:53

2 Answers 2

3

Yes, on Debian-derived systems the canonical location for udev files is /lib/udev. However you shouldn’t have to care about that in your package build, at least if you’re building using a source package: dh_installudev will install them in the right location.

What you need to do is ensure that your rules file ends up available in debian/package.udev, replacing package as appropriate. A symlink is fine, see my solaar package for an example.

The distinction is moot since the /usr merge, but the reason udev files are in /lib is that many of them are essential to booting the system. There isn’t much point in distinguishing essential and non-essential udev files, so they all go in /lib/udev.

1
  • hey, I use solaar! Thanks :) Jan 19, 2023 at 9:28
0

/usr is normally meant for distro-supplied files. External/third-party configurations settings should be installed into /etc. E.g. VirtualBox does exactly that: /etc/udev/rules.d/60-vboxdrv.rules.

You're talking about your own third-party package, so your configuration settings are not to be installed into /usr.

man udev says:

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.

Here's another way to look at it in terms of specifically udev:

# dnf whatprovides '/etc/udev/rules.d/*'
Last metadata expiration check: 1:27:10 ago on Thu 19 Jan 2023 02:17:46 PM +05.
garmintools-0.10-23.fc37.i686 : Tools for Garmin GPS-devices
Repo        : fedora
Matched from:
Filename    : /etc/udev/rules.d/51-garmin.rules

icaro-2.0-11.fc37.noarch : Robotic Educational Project
Repo        : fedora
Matched from:
Filename    : /etc/udev/rules.d/icaro.rules

mISDN-2.0.22-9.fc37.i686 : Userspace part of Modular ISDN stack
Repo        : fedora
Matched from:
Filename    : /etc/udev/rules.d/mISDN.rules

ntp-refclock-0.5-4.fc37.x86_64 : Drivers for hardware reference clocks
Repo        : fedora
Matched from:
Filename    : /etc/udev/rules.d/80-ntp-refclock.rules

... many more packages ...

I'm pretty sure Debian/Ubuntu follow this.

9
  • Regarding your last paragraph, no, Debian/Ubuntu don’t follow this; there is only one package shipping files in /etc/udev/rules.d, and it’s probably an oversight. Jan 19, 2023 at 14:45
  • The number of Fedora's own packages which use /usr/lib/udev/rules.d is far far higher than those which use /etc, so I'm no longer confident in either location. Jan 19, 2023 at 14:57
  • Shipping packaged rules in /etc breaks the whole systemctl edit workflow for local overrides. If you want to avoid shipping rules in /usr/lib, the answer is in your man page quote: /usr/local/lib/udev/rules.d. Jan 19, 2023 at 15:02
  • systemctl edit exists for services and units, not for udev files, AFAIK. Jan 19, 2023 at 15:27
  • Sorry, yes, but the same general idea applies to udev rules: a system administrator is supposed to be able to define overrides in /etc and expect them not to be overwritten by package upgrades. Jan 19, 2023 at 15:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .