首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使sysfs参数值在每次重新引导时保持不变?

如何使sysfs参数值在每次重新引导时保持不变?
EN

Unix & Linux用户
提问于 2022-09-10 11:45:59
回答 2查看 587关注 0票数 1

我必须编写一些sysfs参数文件和每次重新启动。我想知道是否有一种方法可以尽早自动设置这些,最好是在initramfs期间。有规范的方法吗?

我使用lsinitramfs检查负责该sysfs的模块。它们确实存在。例如:asus-wmi.ko,如果我想更改/sys/class/power_supply/BAT0/charge_control_end_threshold

注意到

  • 这一切都应该发生在/挂载之前,因此我更有可能需要直接将文件/配置添加到initramfs,而不是/ disk。
  • 最好是在scripts/local-top/cryptroot之前
EN

回答 2

Unix & Linux用户

发布于 2022-09-10 12:21:06

请注意,由于您提到的特定类是由内核模块添加的,所以在加载模块之前不可能发生篡改。

您可以选择将某些udev规则添加到/etc/udev/rules.d目录中:

代码语言:javascript
复制
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服务:

代码语言:javascript
复制
[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。

票数 1
EN

Unix & Linux用户

发布于 2022-09-10 12:45:02

这就是滑铁卢的作用。

它应该为大多数Linux发行版(如果不是全部)打包。Debian软件包描述说:

代码语言:javascript
复制
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上提供pspgreppkilltop等的包。

最后,如果需要在加载内核模块时设置特定的模块选项,则可以在/etc/modules和.conf文件下使用/etc/modprobe.d/。例如,我在/etc/modprobe.d/zfs.conf中有以下内容:

代码语言:javascript
复制
# use minimum 8GB and maxmum of 16GB RAM for ZFS ARC
options zfs zfs_arc_min=8589934592 zfs_arc_max=17179869184
票数 0
EN
页面原文内容由Unix & Linux提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://unix.stackexchange.com/questions/716798

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档