我必须编写一些sysfs参数文件和每次重新启动。我想知道是否有一种方法可以尽早自动设置这些,最好是在initramfs期间。有规范的方法吗?
我使用lsinitramfs检查负责该sysfs的模块。它们确实存在。例如:asus-wmi.ko,如果我想更改/sys/class/power_supply/BAT0/charge_control_end_threshold。
scripts/local-top/cryptroot之前发布于 2022-09-10 12:21:06
请注意,由于您提到的特定类是由内核模块添加的,所以在加载模块之前不可能发生篡改。
您可以选择将某些udev规则添加到/etc/udev/rules.d目录中:
ACTION=="add", KERNEL=="asus-nb-wmi", RUN+="/bin/bash -c 'echo [TheValueOfYourchoice] > /sys/class/power_supply/BAT?/charge_control_end_threshold'"关照:您提到的是华硕-wmi模块.上述规则适用于asus-nb-wmi模块。你也许应该适应。
或者,如果在systemd下,在/etc/systemd/system目录下创建一个systemd服务:
[Unit]
Description=Set the battery charge end threshold
After=multi-user.target
StartLimitBurst=0
[Service]
Type=oneshot
Restart=on-failure
ExecStart=/bin/bash -c 'echo [TheValueOfYourChoice] > /sys/class/power_supply/BAT0/charge_control_end_threshold'
[Install]
WantedBy=multi-user.target如果您在systemd服务方面已经很聪明了,您就会注意到在加载asus模块之前就启动服务所需的技巧( Restart=on-failure and StartLimitBurst=0 )。
当然,在这两种情况下,都要更改任何有效数字的TheValueOfYourChoice。
发布于 2022-09-10 12:45:02
这就是滑铁卢的作用。
它应该为大多数Linux发行版(如果不是全部)打包。Debian软件包描述说:
Package: sysfsutils
Version: 2.1.1-3
Installed-Size: 62
Maintainer: Guillem Jover <guillem@debian.org>
Architecture: amd64
Depends: libc6 (>= 2.34), libsysfs2 (>= 2.1.1), lsb-base, pci.ids
Pre-Depends: init-system-helpers (>= 1.54~)
Description-en: sysfs query tool and boot-time setup
The sysfs is a virtual file system found in Linux kernels 2.5+ that provides
a tree of system devices. This package provides the program 'systool' to
query it, which can be used to list devices by bus, class, and topology.
.
In addition this package ships a configuration file /etc/sysfs.conf which
allows one to conveniently set sysfs attributes at system bootup (via an
init script).
Description-md5: 07811d91c926da426d94db98052434b1
Multi-Arch: foreign
Homepage: https://github.com/linux-ras/sysfsutils顺便说一下,请参见sysctl和普鲁普中的sysctl.conf,它们为/proc/sys/中的内核参数配置提供了类似的功能。您几乎肯定已经安装了这个包,因为它是在Linux上提供ps、pgrep、pkill、top等的包。
最后,如果需要在加载内核模块时设置特定的模块选项,则可以在/etc/modules和.conf文件下使用/etc/modprobe.d/。例如,我在/etc/modprobe.d/zfs.conf中有以下内容:
# use minimum 8GB and maxmum of 16GB RAM for ZFS ARC
options zfs zfs_arc_min=8589934592 zfs_arc_max=17179869184https://unix.stackexchange.com/questions/716798
复制相似问题