3

The sysctl utility allows a Linux admin to query and modify kernel parameters in runtime. For example, to change the swappiness of a Linux system to 0, we can:

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

Or we can use sysctl:

  1. sysctl -w vm.swappiness=0

To make the value persistent, Archwiki suggests to write vm.swappiness=0 to /etc/sysctl.d/99-swappiness.conf file.

For persistent silent boot, Archwiki suggests to write kernel.printk = 3 3 3 3 to /etc/sysctl.d/20-quiet-printk.conf

Similarly I have a 99-sysrq.conf on my system which works without the number as well.


Archwiki has a sysctl page which mentions the importance of the number:

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.


What does the number in 99-swappiness.conf and 20-quiet-printk.conf denote here?

1
  • Your files “work without the number”? So you have vm.swappiness= and kernel.printk = (i.e., without the number)? OK, I figured out what you meant, in spite of your explanation.  P.S. That page from the Arch Wiki doesn’t “mention the importance of the number”; it only gives an example of a filename that begins with a number (and another example with a filename that doesn’t begin with a number). Commented Mar 3, 2020 at 2:55

3 Answers 3

9

The number at the beginning of the name of configuration files is used as an easily readable way to sort them, with the aim of defining the order of precedence among the entries they contain.

From man 5 sysctl.d1 (emphasis mine):

CONFIGURATION DIRECTORIES AND PRECEDENCE

...

All configuration files are sorted by their filename in lexicographic order, regardless of which of the directories they reside in. If multiple files specify the same option, the entry in the file with the lexicographically latest name will take precedence. It is recommended to prefix all filenames with a two-digit number and a dash, to simplify the ordering of the files.


1 The man page for sysctl.d is shipped as part of the systemd package and the quoted text comes from version 244.3 on Arch Linux. The wording differs to some extent, but not significantly (for the purpose of this Q/A), from both the version currently available at The Linux man-pages project and the version you can find on freedesktop.org.

7

The prefix establishes a natural order the files are read and applied in. In case of conflicting configurations, the settings in highnumber-something will reliably override settings of lownumber-something.

6

Commonly, Linux directories suffixed with .d, such as /etc/sysctl.d or /etc/yum.repos.d, contain configuration files, themselves often suffixed with .conf. The files in these kinds of directories will be sorted and read in lexicographic order.

In order to get files in a .d directory to execute in a desired order, to load some configuration prior to another, then as a convention we prefix the filename with a number to more easily control the order the files are read.

For example, if you had the files:

    10-firstFilename.conf
    20-anotherFile.conf
    30-lastfileToRun.conf

They will be sorted and read in this order.

The same files without the numerical prefix would be sorted in the order:

    anotherFile.conf
    firstFilename.conf
    lastfiletoRun.conf

You can see how the numerical prefix helps implement the desired order.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .