Linux 如何在centos 7(systemd)中持久化sysfs更改
试图在CentOS 7上安装我的苹果键盘上的fn键,我设置了Linux 如何在centos 7(systemd)中持久化sysfs更改,linux,centos,systemd,Linux,Centos,Systemd,试图在CentOS 7上安装我的苹果键盘上的fn键,我设置了 $ cat /etc/modprobe.d/hid_apple.conf options hid_apple fnmode=2 但在重启之后 $ cat /sys/module/hid_apple/parameters/fnmode 1 互联网上的建议包括运行更新initramfs,这在Centos 7上似乎不存在,以及在/etc/rc.local中执行“echo 2>>/sys/module/hid_apple/paramete
$ cat /etc/modprobe.d/hid_apple.conf
options hid_apple fnmode=2
但在重启之后
$ cat /sys/module/hid_apple/parameters/fnmode
1
互联网上的建议包括运行更新initramfs,这在Centos 7上似乎不存在,以及在/etc/rc.local中执行“echo 2>>/sys/module/hid_apple/parameters/fnmode”,当然在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
然后执行此操作以使服务在引导时运行
sudo systemctl enable hid_apple_fnmode_set.service
根据udev规则:
# /etc/udev/rules.d/99-hid_apple.rules
SUBSYSTEM=="module", DRIVER=="hid_apple", ATTR{parameters/fnmode}="2"
systemd脚本和udev规则是通过一些猜测组合在一起的,可能需要一些调整才能工作。以下命令有助于调整和调试udev规则:
udevadm info --attribute-walk --path=/module/hid_apple
udevadm test /sys/module/hid_apple/
使用tmpfiles.d机制,例如,将apple-hid.conf放置到/etc/tmpfiles.d,并包含以下内容
w /sys/module/hid_apple/parameters/fnmode - - - - 2
哦,很抱歉,这篇文章是打字错误造成的。在hid_apple.conf和/sys/module/下的文件名中是“fnmode”。。。。我已经修复了帖子,谢谢。你能给我一个关于systemd解决方案的提示吗?或者至少是一个指向它的指针?这是我第一次使用systemd系统。我修改了答案,看看这些答案是否对你有用。哇,这是一个多么好的答案,你刚刚完全引导了我对systemd和udev的理解。谢谢,@Angelos<代码>内核==“hid_apple”子系统==“module”,驱动程序==”,ATTR{parameters/fnmode}=“2”为meThis工作是一个出色的黑客,也是一个非常友好的工具。创建文件后,确保运行
systemd tmpfiles--create
将systemd tmpfiles
写入/sys
。谢谢你的提示!