如何使用内核命令行参数设置 sysctl?

adr*_*nos 5 linux command-line grub2 sysctl kernel-parameters

是否可以使用内核命令行(在 中可见的那些)设置 Linux 内核sysctl设置(那些通常在 中设置)?/etc/sysctl.d/proc/cmdline

(使用grub配置文件/etc/default/grub变量GRUB_CMDLINE_LINUX="..."。)

小智 8

从内核版本5.8开始,可以通过内核命令行设置 Sysctl 参数,这要归功于SUSE 的Vlastimil Babka。

sysctl.*=       [KNL]
                Set a sysctl parameter, right before loading the init
                process, as if the value was written to the respective
                /proc/sys/... file. Both '.' and '/' are recognized as
                separators. Unrecognized parameters and invalid values
                are reported in the kernel log. Sysctls registered
                later by a loaded module cannot be set this way.
                Example: sysctl.vm.swappiness=40
Run Code Online (Sandbox Code Playgroud)