Score:1

How do I write a udev rule to persist an attribute on boot?

th flag

I want to persist the value of /sys/devices/platform/lg-laptop/fn_lock to be 1 after a reboot. After doing a lot of research, it seems that the right way to do this is to create a udev rule for it. So I ran udevadm info -a -p /sys/devices/platform/lg-laptop/ which returns this:

looking at device '/devices/platform/lg-laptop':
    KERNEL=="lg-laptop"
    SUBSYSTEM=="platform"
    DRIVER=="lg-laptop"
    ATTR{battery_care_limit}=="0"
    ATTR{driver_override}=="(null)"
    ATTR{fan_mode}=="0"
    ATTR{fn_lock}=="0"

And I made a file /etc/udev/rules.d/99-fnlock.rules with the following content:

ACTION=="change", KERNEL=="lg-laptop", SUBSYSTEM=="platform", ATTRS{fn_lock}="1"

But it doesn't seem to have any effect when I reboot. Is my syntax wrong, or am I misunderstanding how to set attributes with udev?

Score:1
th flag

The correct syntax for the rules file was:

SUBSYSTEM=="platform", DRIVER=="lg-laptop", ATTR{fn_lock}="1"

I think my mistake was probably ATTRS{fn_lock} instead of ATTR{fn_lock}, since the matching rules (ones with == operator) seem to be a bit flexible.

user.dz avatar
ng flag
It will be easier to find, if set as accepted. Thank you for sharing the solution.
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.