List and Change Kernel Config Variables With Sysctl Command

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/list-and-change-kernel-config-variables-with-sysctl-command/
PINTEREST
PINTEREST
INSTAGRAM

Linux operating systems run  on the kernel actually Linux kernel. The kernel name is Linux but the distributions are generally named as Linux. Kernel provides operating system services to the user space applications. Kernel have a lot of option and configurations possibilities to meet user space applications, libraries and system administrator needs. These configurations may be IP stack, disk read limit, loaded modules etc. There are different ways to manage this configuration variables or kernel parameters. Sysctl is a tool which provides easy configuration of these kernel parameter.

Syntax

Help

Help

Help

Kernel Parameter Configuration File

Linux Kernel configuration is stored in a file named sysctl.conf . This file is locate at /etc . Following is a sample part from this configuration file.

There is also a directory named sysctl.d which holds configuration files too. There are some prepared files by operating system. For example kernel hardening configurations can be put into 10-kernel-hardening.conf file for easy management. This files are generally used to make configuration persistent and effect through boots.

LEARN MORE  Vi/Vim Show Line Numbers

Display Kernel Parameters

Previous part we have examined configuration files. These files only stores some of the kernel configuration variables. There are some default values those can not configured explicitly. Default configuration parameters can be listed with -a option which means all.

Display Kernel Parameters

Display Kernel Parameters

As we can see from screenshot the parameters are arranged like

there is a lot of parameters we can not list here.

Display Specific Kernel Parameter

In previous example we listed all kernel parameters. There are a lot of kernel parameters which will fill our screen. If we just want to get a single parameter we can specify it to list. But we need the exact name of the parameter. If we do not know exact name but some part of the name we can filter it. To learn filtering look example below.

Next line provide the value vm.laptop_mode currently holding.

Filter Kernel Parameters

We can easily list single kernel parameter with -n option. But what if we want to list a whole category or we only know some part of the kernel parameter name? We can use grep tool to find what we want. In the example we will list kernel parameter those names have the term laptop

Kernel Parameter Categories

There a different type of kernel parameter categories. We will look them briefly with most popular parameters names.

  • device category used to set connected devices information, hid, mouse click key codes, raid speeds etc.
  • fs category is used to store file system related nfs configuration, quoata parameters etc.
  • kernel category provides kernel related config hostname, numa, pty, random entropy etc.
  • net category provides network related parameters like appletalk, ipv4, ipv6 stack, icmp, route
  • vm category provides memory configuration like huge pages, over commit, swap, laptop mode etc.
LEARN MORE  Linux Scheduling Commands With at, atq, atrm and batch Examples

Set Kernel Parameter Temporarily

Kernel parameters can be changed from user space with sysctl. To change this parameters we need root privilege because it will effect system wide. In this example we will change the vm.laptop_mode and set it true.

Set Kernel Parameter Persistently

In previous example we have set the kernel parameter but it is temporary. After a reboot this kernel parameter will be set to its default value which is 0. We can prevent the lost of kernel parameter values and settings by writing them in to persistent configuration file. We looked these configuration files in the beginning of the tutorial. The simplest way is adding following line to the /etc/sysctl.conf file

OR more tidy and manageable way is create a file as /etc/sysctl.d/30-laptop for this type of laptop settings and and ad to this file.

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/list-and-change-kernel-config-variables-with-sysctl-command/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)