- Updating Configuration Files
- Configure Kernel Options
- Configure Common System Services
- Localization
Configure Kernel Options
The Linux kernel is highly configurable. You can make changes to the kernel by using parameters and kernel modules. This section covers these configuration features.
Parameters
A kernel parameter is a value that changes the behavior of the kernel.
sysctl
You can view and change parameters by using the sysctl command. For example, to view all the kernel and kernel module parameters, execute the sysctl command with the -a option:
[root@onecoursesource ~]# sysctl -a | head kernel.sched_child_runs_first = 0 kernel.sched_min_granularity_ns = 1000000 kernel.sched_latency_ns = 5000000 kernel.sched_wakeup_granularity_ns = 1000000 kernel.sched_tunable_scaling = 1 kernel.sched_features = 3183 kernel.sched_migration_cost = 500000 kernel.sched_nr_migrate = 32 kernel.sched_time_avg = 1000 kernel.sched_shares_window = 10000000
The name of the parameter (kernel.sched_child_runs_first, for example) is a relative pathname that starts from /proc/sys and has a dot (.) character between the directory and filename rather than a slash (/) character. For example, the /proc/sys/dev/cdrom/lock file is named using the dev.cdrom.lock parameter:
[root@onecoursesource ~]# sysctl -a | grep dev.cdrom.lock dev.cdrom.lock = 1
You can change the value of this parameter by using the sysctl command:
[root@onecoursesource ~]# sysctl dev.cdrom.lock=0 dev.cdrom.lock = 0 [root@onecoursesource ~]# sysctl -a | grep dev.cdrom.lock dev.cdrom.lock = 0
It is actually safer to use the sysctl command than to modify the file directly because the sysctl command knows which values for the parameter are valid and which ones are not:
[root@onecoursesource ~]# sysctl dev.cdrom.lock="abc" error: "Invalid argument" setting key "dev.cdrom.lock"
The sysctl command knows which parameter values are valid because it can look at the modinfo output. For example, the value of the lock file must be a Boolean (0 or 1), according to the output of the modinfo command:
[root@onecoursesource ~]# modinfo cdrom | grep lock parm: lockdoor:bool
If you modify the file directly or use the sysctl command, the changes are temporary. When the system is rebooted, the values go back to the defaults, unless you make changes in the /etc/sysctl.conf file. The next section provides more details about /etc/sysctl.conf.
/etc/sysctl.conf
The /etc/sysctl.conf file is used to specify which kernel parameters to enable at boot.
Example:
[root@OCS ~]# cat /etc/sysctl.conf # System default settings live in/usr/lib/sysctl.d/00-system.conf. # To override those settings, enter new settings here, or # in an /etc/sysctl.d/<name>.conf file. # # For more information, see sysctl.conf(5) and sysctl.d(5). net.ipv4.ip_forward=1
In this example, the kernel parameter ip_forward is turned on, which means this machine will act as a router between two networks.
There are thousands of possible kernel settings, including dozens of settings that affect networking. The ip_forward setting is one of the most common network settings.
The parameters that optimize the IO (input/output) scheduler are examples of kernel parameters. Several parameters can be set to change the behavior of the scheduler. This section covers the parameters that are important for the Linux+ XK0-005exam.
To see the current scheduler, view the contents of the /sys/block/<device>/queue/scheduler file (where <device> is the actual device name). Here’s an example:
[root@OCS ~]# cat /sys/block/sda/queue/scheduler [noop] deadline cfq
The value within the square brackets is the default. To change this, use the echo command, as shown here:
[root@OCS ~]# echo "cfq" > /sys/block/sda/queue/scheduler [root@OCS ~]# cat /sys/block/sda/queue/scheduler noop deadline [cfq]
Additional scheduler types include the following:
cfq: The Completely Fair Queuing schedule has a separate queue for each process, and the queues are served in a continuous loop.
noop: This schedule follows the FIFO (first in, first out) principle.
deadline: This is the standard scheduler. This scheduler creates two queues: a read queue and a write queue. It also puts a timestamp on each I/O request to ensure that requests are handled in a timely manner.
Modules
A module is a small software program that, when loaded, provides more features and capabilities to the kernel. This section describes the management of modules using the lsmod, imsmod, rmmod, insmod, modprobe, and modinfo commands.
lsmod
The lsmod command displays the kernel modules that are loaded into memory. This command has no options.
In the output of the lsmod command, each line describes one module. There are three columns of information for each line:
The module name.
The size of the module, in bytes.
The “things” that are using the module. A “thing” could be a filesystem, a process, or another module. In the event that another module is using this module, the dependent module name is listed. Otherwise, a numeric value that indicates how many “things” use this module is provided.
Example:
[root@OCS ~]# lsmod | head Module Size Used by tcp_lp 12663 0 bnep 19704 2 bluetooth 372944 5 bnep rfkill 26536 3 bluetooth fuse 87741 3 xt_CHECKSUM 12549 1 ipt_MASQUERADE 12678 3 nf_nat_masquerade_ipv4 13412 1 ipt_MASQUERADE tun 27141 1
imsmod
The imsmod command is used to add modules to the currently running kernel.
Syntax:
insmod [module_name]
The exact location of the module needs to be specified. For example:
[root@OCS ~]# lsmod | grep fat [root@OCS ~]# insmod /usr/lib/modules/3.19.8-100.fc20.x86_64/kernel/ fs/ fat.ko [root@OCS ~]# lsmod | grep fat fat 65107 0
There are no options to the insmod command; however, each module might have modules that can be passed into the module using the following syntax:
insmod module options
The insmod command has two disadvantages:
You have to know the exact location of the module.
If the module has any dependencies (that is, if the module needs another module), it will fail to load.
rmmod
The rmmod command is used to remove modules from the currently running kernel.
Syntax:
rmmod [options] [module_name]
Example:
[root@OCS ~]# lsmod | grep fat fat 65107 0 [root@OCS ~]# rmmmod fat [root@OCS ~]# lsmod | grep fat
Modules that are currently in use will not be removed by this command by default.
Key options for the rm command include the following:
-f attempts to force removal of modules that are in use (which is very dangerous).
-w waits for a module to be no longer used and then removes it.
-v displays verbose messages.
insmod
The insmod command is used to add modules to the currently running kernel.
Syntax:
insmod [module_name]
The exact location of the module needs to be specified. For example:
[root@OCS ~]# lsmod | grep fat [root@OCS ~]# insmod /usr/lib/modules/3.19.8-100.fc20.x86_64/kernel/ fs/ fat.ko [root@OCS ~]# lsmod | grep fat fat 65107 0
There are no options to the insmod command; however, each module might have modules that can be passed into the module using the following syntax:
insmod module options
The insmod command has two disadvantages:
You have to know the exact location of the module.
If the module has any dependencies (that is, if the module needs another module), it will fail to load.
modprobe
The modprobe command is used to add and remove modules from the currently running kernel. It also attempts to load module dependencies.
Syntax:
modprobe [options] [module_name]
When used to remove modules (with the -r option), the modprobe command also removes dependency modules unless they are in use by another part of the subsystem (such as the kernel or a process).
Key options for the modprobe command include the following:
-c displays the current modprobe configuration.
-q causes modprobe to run in quiet mode.
-R displays all modules that match an alias to assist you in debugging issues.
-r removes the specified module from memory.
-v displays verbose messages; this is useful for determining how modprobe is performing a task.
modinfo
The modinfo command is used to provide details about a module.
Syntax:
modinfo [module_name]
Example:
[root@OCS ~]# modinfo xen_wdt filename: /lib/modules/3.19.8-100.fc20.x86_64/kernel/drivers/watchdog/ xen_wdt.ko license: GPL version: 0.01 description: Xen WatchDog Timer Driver author: Jan Beulich <jbeulich@novell.com> srcversion: D13298694740A00FF311BD0 depends: intree: Y vermagic: 3.19.8-100.fc20.x86_64 SMP mod_unload signer: Fedora kernel signing key sig_key: 06:AF:36:EB:7B:28:A5:AD:E9:0B:02:1E:17:E6:AA:B2:B6:52: 63:AA sig_hashalgo: sha256 parm: timeout:Watchdog timeout in seconds (default=60)(uint) parm: nowayout:Watchdog cannot be stopped once started (default=0) (bool)
One of the most important parts of the output of the modinfo command is the parm values, which describe parameters that can be passed to this module to affect its behavior.