How to make sysfs changes permanent on centos 7 (systemd)

Trying to fix fn keys on my Apple keyboard on CentOS 7, I installed

$ cat /etc/modprobe.d/hid_apple.conf
options hid_apple fnmode=2

      

and still after reboot

$ cat /sys/module/hid_apple/parameters/fnmode
1

      

The internet suggests runs update-initramfs that don't seem to exist on Centos 7 and does "echo 2 -> / sys / module / hid_apple / parameters / fnmode" in /etc/rc.local which of course doesn't exists in the system.

What's the correct way to keep this setting?

+3


source to share


1 answer


There are three ways to achieve this goal:

  • rc.local (still works, remember chmod + x after adding lines)
  • Systemd
  • udev rules (My preference)

With systemd:

# /etc/systemd/system/hid_apple_fnmode_set.service 
[Unit]
Description=Set Apple keyboard fn mode
After=multi-user.target

[Service]
ExecStart=/usr/bin/bash -c '/usr/bin/echo 2 > /sys/module/hid_apple/parameters/fnmode'

[Install]
WantedBy=graphical.target

      

This is followed by this to start the service at boot.



sudo systemctl enable hid_apple_fnmode_set.service

      

With udev rules:

# /etc/udev/rules.d/99-hid_apple.rules
SUBSYSTEM=="module", DRIVER=="hid_apple", ATTR{parameters/fnmode}="2"

      

Systemd script and udev rules combined with some wild guesses may need some tweaking to work. The following commands can help you configure and debug your udev rule:

udevadm info --attribute-walk --path=/module/hid_apple

udevadm test /sys/module/hid_apple/

      

+5


source







All Articles