sysctl 配置文件中的数字表示什么?

What does the number in sysctl configuration file denote?

sysctl 实用程序允许 Linux 管理员在运行时查询和修改内核参数。例如,要将 linux 系统的 swappiness 更改为 0,我们可以:

  1. echo 0 > /proc/sys/vm/swappiness

或者我们可以使用 sysctl

  1. sysctl -w vm.swappiness=0

要使值持久化,Archwiki suggestsvm.swappiness=0 写入/etc/sysctl.d/99-swappiness.conf 文件。

对于持久性 silent boot,Archwiki 建议将 kernel.printk = 3 3 3 3 写入 /etc/sysctl.d/20-quiet-printk.conf

同样,我的系统上有一个 99-sysrq.conf,它也可以在没有号码的情况下工作。


Archwiki 有一个 sysctl page 提到了数字的重要性:

Note: From version 207 and 21x, systemd only applies settings from /etc/sysctl.d/.conf and /usr/lib/sysctl.d/.conf. If you had customized /etc/sysctl.conf, you need to rename it as /etc/sysctl.d/99-sysctl.conf. If you had e.g. /etc/sysctl.d/foo, you need to rename it to /etc/sysctl.d/foo.conf.


99-swappiness.conf20-quiet-printk.conf中的数字在这里表示什么?

这是读取文件的顺序。通过在它前面加上一个两位数的数字,您可以简单地按其字符的 ascii 值进行排序。 20-quiet….conf99-swapiness.conf 之前。 (尝试使用 ls 默认排序)。

这遵循 SysV 初始化系统已经使用的约定。引自非常有用的 boot 联机帮助页的 测序目录 部分:

To define the starting or stopping order within the same run-level, the name of a link contains an order-number. Also, for clarity, the name of a link usually ends with the name of the service to which it refers. For example, the link /etc/rc2.d/S80sendmail starts the sendmail service on runlevel 2. This happens after /etc/rc2.d/S12syslog is run but before /etc/rc2.d/S90xfs is run.