In this lesson,
we'll explore how to change both persistent and
non persistent runtime parameters for the Linux kernel.
Now kernel runtime parameters is just a fancy term for what are
basically settings for how the Linux kernel does its job internally.
Since the kernel deals with low level stuff like allocating memory handling,
network traffic and so on.
Most of these settings revolve around these things
to see all kernel runtime parameters currently in use, enter this command
CCTL dash A,
not all parameters can be read,
we'll occasionally see lines like this,
the permission denied.
If we want to make sure that all parameters are displayed,
we can run the previous command with root privileges.
Let's take a look at a parameter and its value.
This naming convention makes it quite easy to figure out what the parameter does.
Everything that starts with net dot
is some kind of network related parameter.
Memory related stuff will start with VM dot
As in virtual memory
file system settings in the Linux kernel start with FS dot
So we can figure out that our parameter is related
to IPv6 or internet protocol version six and it disables something
with a value of zero. It means that this does not disable anything.
Zero. Basically means false. In this case. While one means true
to make it disable this, we would need to set it to one
and to set the value of this parameter, we can use this command
dash W is the option to write a value to a parameter.
Make sure there is no space before or after the equal sign.
But this is a non persistent change to the parameter.
It will be active from now on if our operating system continues to run.
But as soon as we reboot it,
then this setting will be set to zero. Once again, it's default value.
So a nonpersistent change like we did here does not survive across reboots.
We'll soon learn how to make this change persistent.
Now to check the current value for a parameter,
we just type CCTL followed by the exact name of that parameter.
So how do we make a change persistent?
We can add a file to the Etsy CCTL dot D directory.
But it's important to remember that this file has to end with a.com extension
conf
it's easy to forget that.
So to get a refresh on how we use this directory,
we can type in MSIS
TL dot D
and we will immediately see that the.com
extension is required.
We can also run the LS command on that directory
and we'll notice a few comp files already
in there reminding us about the required extension and
also serving as inspiration on how to use these
files since we can look at their contents,
we can see how they're built.
Now, let's say we want to look only at memory related parameters.
We mentioned that they start with VM dot
So we could use the CCTL dash A command to display all parameters and
then filter with grep to only show stuff that contains the text BM.
Now with VM dot Swappiness equals 60
users often configure this parameter when they want to change how
Linux behaves when it starts to run out of free memory.
A technique called swapping can move data from
memory to a storage device like an SSD.
This can temporarily free up some memory so it can be used by other programs.
The swappiness value can be anything between zero and 100 on older kernels
and between zero and 200 on newer kernels
with a higher value. We basically tell the Linux kernel hey,
swap whenever you want to, even at the slightest sign, you're running low on memory
and with a lower value, we tell it, hey, avoid swapping at all costs.
Only do this when absolutely necessary.
Now, let's say we want to change this value to 20
make the change persistent
meaning if we reboot
it'll still be set to that value.
Now, first, we could create a comp
file in Etsy
CTL dot D
swap dash less dot conf and in this file, we'll simply add this content.
VM dot Swappiness equals 20
then save our file.
Now,
every time our Linux operating system boots this parameter
will be set to the value of 20.
The parameter is now persistent
but there's a catch
until the next boot swappiness will still be using the old value of 60.
If we want to make Linux immediately adjust parameters
in the way that we define them in our file, we should also run this command.
The manpage for CCTL does not really say why this option is called dash P.
But you can think of it as a reading
settings from a permanent file to remember this later.
It's worth noting that another place we can edit kernel parameters is in the Etsy
sis ctl.com file.
So we can run a command like this
and edit it directly.
What's interesting about this file is that it
includes explanations about important and often change parameters
so it can give us a bit of extra context
on what some parameters do before we actually change them.
Plus it conveniently places those parameters in that file and they're
easy to turn on just by uncommenting their respective lines.
But keep in mind that that file can be
accidentally overwritten when you're upgrading the operating system.
So if you intend to make persistent changes of your
own place them in the Etsy CCTL dot D directory instead