Score:1

Doing an udev rule at boot time

cn flag

I have a service that I want to run, only after udev has set the correct permissions on device files.

This seems to go wrong at boot time: My service is started, with the /dev/hidraw0 file permissions not yet set.

My service is defined as:

# cat /lib/systemd/system/turboledz.service 
[Unit]
Description=Turbo LEDz service
After=systemd-udevd.service

[Service]
Type=simple
User=daemon
ExecStart=/usr/bin/turboledzd
KillMode=control-group

[Install]
WantedBy=multi-user.target

And I can see its dependency:

# systemctl list-dependencies turboledz
turboledz.service
● ├─system.slice
● └─sysinit.target
●   ├─apparmor.service
●   ├─dev-hugepages.mount
●   ├─dev-mqueue.mount
●   ├─keyboard-setup.service
●   ├─kmod-static-nodes.service
●   ├─plymouth-read-write.service
●   ├─plymouth-start.service
●   ├─proc-sys-fs-binfmt_misc.automount
●   ├─setvtrgb.service
●   ├─sys-fs-fuse-connections.mount
●   ├─sys-kernel-config.mount
●   ├─sys-kernel-debug.mount
●   ├─sys-kernel-tracing.mount
○   ├─systemd-ask-password-console.path
○   ├─systemd-binfmt.service
○   ├─systemd-boot-system-token.service
○   ├─systemd-hwdb-update.service
●   ├─systemd-journal-flush.service
●   ├─systemd-journald.service
○   ├─systemd-machine-id-commit.service
●   ├─systemd-modules-load.service
○   ├─systemd-pstore.service
●   ├─systemd-random-seed.service
●   ├─systemd-sysctl.service
●   ├─systemd-sysusers.service
●   ├─systemd-timesyncd.service
●   ├─systemd-tmpfiles-setup-dev.service
●   ├─systemd-tmpfiles-setup.service
●   ├─systemd-udev-trigger.service
●   ├─systemd-udevd.service
●   ├─systemd-update-utmp.service
●   ├─cryptsetup.target
●   ├─local-fs.target
●   │ ├─-.mount
●   │ ├─boot-efi.mount
●   │ ├─mnt-farm0.mount
●   │ ├─mnt-farm1.mount
●   │ ├─mnt-farm2.mount
●   │ ├─mnt-farm3.mount
●   │ ├─mnt-farm4.mount
●   │ ├─mnt-farm5.mount
○   │ ├─systemd-fsck-root.service
●   │ └─systemd-remount-fs.service
●   ├─swap.target
●   │ └─swapfile.swap
●   └─veritysetup.target

The permission should have been taken care of, with this rule:

# cat /lib/udev/rules.d/70-turboledz.rules 
# Make Vendor "Arduino LLC", Product "Arduino Micro" accessible for non-root users.
# Note: BUS 1 is USB.

SUBSYSTEMS=="usb", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="8037", MODE="0666"

KERNEL=="hidraw*", ATTRS{busnum}=="1", ATTRS{idVendor}=="2341", ATTRS{idProduct}=="8037", MODE="0666"

Normally, this rule properly sets the permission when I plug in the device.

But at boot time, it does not seem to get run?

Do all udev rules run during boot?

UPDATE:

I see that eventually the rule does get run, as after boot, when I log into the machine, I see the correct permissions.

It appears that the rule is just applied to late for my service.

OS: Ubuntu 21.10

CPU: i5-11600K

Kernel: Linux i7 5.13.0-22-generic

Systemd: 248.3-1ubuntu8

user.dz avatar
ng flag
Could you test if `sudo update-initramfs -u` helps?
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.