6

I made some changes to sysctl.conf but now need to run sysctl -p on each boot. I can always create an init script to have it run automatically on boot, but I was wondering if there was an Ubuntu / Debian way of doing it.

cmdematos
  • 249
  • 2
  • 6

3 Answers3

3

There is a better and more ellegant way:

create your configuration file on /etc/sysctl.d/ directory.

For example, if you changing kernel parameters due to database requirements, create a file:

/etc/sysctl.d/60-mysql.conf

and add your own parameters inside it. To execute it:

service procps restart

Just to note:

  • procps is a system file and it should NEVER be edited.

  • /etc/sysctl.conf should not be edited either because it can be changed on a system/kernel upgrade and if it's differente from expected, upgrade will be halted asking if newer version can replace current one.

Reference: http://manpages.ubuntu.com/manpages/precise/man8/sysctl.8.html

josircg
  • 1,220
  • 1
  • 15
  • 23
2

You add your desired sysctls into /etc/sysctl.conf and they will be applied at boot time. However, if you have updated /etc/sysctl.conf and what to apply it immediately, run:

sudo sysctl --system
Colin Ian King
  • 18,370
  • 3
  • 59
  • 70
  • It's actually `sysctl -p` to reload `/etc/sysctl.conf` file. You can also read the settings from your own file, by specifying it after the `-p` option, for example `sysctl -p /home/user/custom.conf`. – Cleankod Jan 15 '14 at 14:33
0

On Ubuntu the Upstart job procps (/etc/init/procps.conf) already does that for you.

Florian Diesch
  • 86,013
  • 17
  • 224
  • 214
  • 1
    Hi Florian, I understand that your post has the intention to be educational. But an unwary user could imagine that he/she have to edit procps.conf what would be a disaster, don't you agree? – josircg Feb 22 '14 at 12:56
  • it turns out there is more than just `sysctl.conf` and `procps.conf`: [the issue with pm-utils and laptop-mode](https://askubuntu.com/questions/443032/etc-sysctl-conf-doesnt-persist-after-reboot) – xealits Nov 09 '17 at 11:58