change kernel parameters in linux

How to Change Kernel Parameters At Runtime

Just as you can use GRUB loader to modify the boot process, you can also change kernel parameters at runtime for the same. You can use terminal command to modify kernel parameters or edit them in configuration file. They allow you to change kernel parameters on the fly to change boot behavior process. In this article, we will learn how to change kernel parameters at runtime.

How to Change Kernel Parameters At Runtime

Before we proceed, we need to know more about /proc directory in Linux. It contains information about default method for handling process & system information, and kernel & memory information. /proc/sys is where you can find all information about drivers, devices and some kernel features. Here are the steps to change kernel parameters at runtime using sysctl command.

You can view the complete list of available kernel parameters using the following command.

# sysctl -a 

If you just want a count of these parameters, you can pass the above command’s output to wc command.

# sysctl -a | wc -l

Please note, the sysctl -a command’s output may contain a lot of lines since there are many kernel parameters you can pass it to commands like less to view pagewise output.

# sysctl -a | less

Here is a sample output.

Please note, the first few characters of each line match the directory names in /proc/sys directory. Here is an example. You will see that sr0 is the name used by kernel to identify the drive. = drive name:        	sr0

Here are the commonly found prefixes in this file and what they mean.

  1. dev: parameters for specific devices connected to the machine.
  2. fs: filesystem configuration (quotas and inodes, for example).
  3. kernel: kernel-specific configuration.
  4. net: network configuration.
  5. vm: use of the kernel’s virtual memory.

Here are couple more examples about what different parameters mean.

dev.cdrom.autoclose → /proc/sys/dev/cdrom/autoclose
net.ipv4.ip_forward → /proc/sys/net/ipv4/ip_forward

If you want to view the value of a specific kernel parameter, you can do so by mentioning it after sysctl command or reading the associated file. Here are some examples.

# sysctl dev.cdrom.autoclose
# cat /proc/sys/dev/cdrom/autoclose
# sysctl net.ipv4.ip_forward
# cat /proc/sys/net/ipv4/ip_forward

Modify or Set Kernel Parameters

You can set or modify kernel parameters using sysctl command with -w option, or using echo to directly write the associated file. Here are the commands to disable packet forwarding in our system

# echo 0 > /proc/sys/net/ipv4/ip_forward
# sysctl -w net.ipv4.ip_forward=0

Please note, the above commands only set the kernel parameters during the current session and are reset during system reboot.

To set these values permanently, you need to modify them in /etc/sysctl.conf configuration file. For example, open the file in a text editor. But before you edit this file, it is advisable to take a backup of the same so that if there are any issues later on, you can use the backup file to restore the original file.

$ sudo cp /etc/sysctl.conf /etc/sysctl-backup.conf
$ vi /etc/sysctl.conf

Add the following line to it.


Save and close the file. Then run the following command to apply changes.

# sysctl -p

In this article, we have learnt how to change kernel parameters during system boot. To recap, kernel parameters allow you to easily change kernel settings during system boot sequence. Generally, it is done by modify GRUB boot loader but you can also do this from within Linux via terminal commands or by editing configuration file. If you use terminal commands the kernel parameters will be reset during system boot. To permanently change these parameters, you need to edit their configuration file.

Also read:

How to Install Kernel Headers in RHEL & CentOS
How to Install Kernel Headers in Ubuntu & Debian
How to Migrate from GitHub to BitBucket
How to Transfer All MySQL Databases from One Server to Another
How to List All Virtual Hosts in NGINX

Leave a Reply

Your email address will not be published.