Posts Tagged ‘ Kernel ’

kernel parameters & Sysctl

There are lot of kernel parameters and those parameters can be viewed from /proc/sys/ directory. Modification of values of these parameters will persit only until the next reboot of the system.

We can modify these kernel parameter values manually. i.e. by echoing new values to files in /proc/sys/ [Each parameters have a file in /proc/sys/ directory].

sysctl provides CLI interface for editing/viewing these parameters. It has various options too.

I am going to exaplain little more about kernel parameters with an example.

hostname is a kernel parameter which stores hostname of the system. Its location is "/proc/sys/kernel/hostname"

The value for this parameter is loaded to kernel by rc.sysinit file during the boot process.

[root@ ~]# cat /etc/rc.sysinit

#!/bin/bash

#

# /etc/rc.d/rc.sysinit - run once at boot time

#

# Taken in part from Miquel van Smoorenburg's bcheckrc.

#

 

HOSTNAME=$(/bin/hostname)

Note :I truncated the remaining portion of this file since currently we are only intrested in HOSTNAME

So while booting the OS we pass the value of hostname to kernel through rc.sysinit file and hence changing the hostname through /etc/sysconfig/network file needs rebooting the OS to take into effect.

Alternatively we can change the hostname without any reboot by following method.

[root@ ~]# hostname

host1.server2.com

[root@ ~]# vi /etc/sysconfig/network # Edit the value for HOSTNAME to host2.server2.com

[root@ ~]# sysctl -w kernel.hostname="host2.server2.com"

[root@ ~]# bash

[root@ ~]# hostname

host2.server2.com

This can also be done via echoing new value to /proc/sys/kernel/hostname

Like this:

echo host2.server2.com > /proc/sys/kernel/hostname

Note : I mean this article only for make you undestatnd about the kernel parameters and its values. The simplest way for modifying the hostname is by using /bin/hostname

Parameters available for sysctl

variable

The name of a key to read from.  An example is kernel.ostype.  The ’/’ separator is also accepted in place of a ’.’.

variable=value

To set a key, use the form variable=value, where variable is the key and value is the value to set it to. If the value contains quotes or characters which are parsed by the shell, you may need to enclose the value in double quotes. This requires the -w parameter to use.

-n Use this option to disable printing of the key name when printing values.

-e Use this option to ignore errors about unknown keys.

-N Use this option to only print the names. It may be useful with shells that have programmable completion.

-q Use this option to not display the values set to stdout.

-w Use this option when you want to change a sysctl setting.

-p Load in sysctl settings from the file specified or /etc/sysctl.conf if none given. Specifying – as filename means reading data from standard input.

-a Display all values currently available.

-A Display all values currently available in table form.

Examples:

/sbin/sysctl -a

/sbin/sysctl -n kernel.hostname

/sbin/sysctl -w kernel.domainname=”example.com”

/sbin/sysctl -p /etc/sysctl.conf

We can add persistance to the kernel values by editing/adding values in /etc/sysctl.conf

[root@host13 ~]# cat /etc/sysctl.conf

# Kernel sysctl configuration file for Red Hat Linux

#

# For binary values, 0 is disabled, 1 is enabled.  See sysctl(8) and

# sysctl.conf(5) for more details.

# Controls IP packet forwarding

net.ipv4.ip_forward = 0

# Controls source route verification

net.ipv4.conf.default.rp_filter = 1

# Do not accept source routing

net.ipv4.conf.default.accept_source_route = 0

# Controls the System Request debugging functionality of the kernel

kernel.sysrq = 0

# Controls whether core dumps will append the PID to the core filename.

# Useful for debugging multi-threaded applications.

kernel.core_uses_pid = 1

# Disable netfilter on bridges.

net.bridge.bridge-nf-call-ip6tables = 0

net.bridge.bridge-nf-call-iptables = 0

net.bridge.bridge-nf-call-arptables = 0

Manually Compile a Linux Kernel

Normally we prefer to just use the RPM method to install a Linux kernel on a server, which is definitely easy and cause less trouble to get the server working. However if you are comfortable with Linux structure and what to have a customized Linux Kernel on your server with the Modules of your choice then here are the steps for you. These steps can be used for Valina as well as standard kernels.

How to compile kernel manually?
There are two ways to compile a kernel:
1. Install a RPM package.
2. An orthodox method of doing it manually.

This tutorial will show you the orthodox method.

*** Steps to compile a kernel on Linux server. ***
(Estimated time is 45-60 mins)

The Pre-Compilation Stage.

1. Login as root into the server.

2. Copy the current modules listed in lsmod command in a notepad.
Code:

lsmod

3. Check the CPU configuration of the system.
Code:

cat /proc/cpuinfo

4. Copy the grub.cong file in a notepad.
Code:

cat /boot/grub/grub.conf

5. Goto /usr/src/
Code:

cd /usr/src/

6. Download kernel you require from kernel.org
Code:

wget http://www.kernel.org/pub/linux/kernel/v2.6/linux-x.x.x.x.tar.gz

(Where x.x.x.x is the make of the kernel)

7. untar the zipped file.
Code:

tar zxf linux-2.6.15.4.tar.gz

8. Goto in the folder extracted
Code:

cd linux-2.6.15.4/

——–Compilations Stage.——–

You have a number of ways of going through the possible modules to include.

make config: A sequential text-based selection method. Takes a loooooong time.
make menuconfig: uses a text-terminal pseudo-graphic interface.
make xconfig: A version of menuconfig for X Window if you have it running. You need to have X server running to use this step.

But we will use the oldconfig method since we do not want to make any major changes which might end up being a complete mess.

Before we fire the oldconfig command we will have to copy the old configuration in the new Linux kernel.
And to do that we will have to check the current version kernel installed on the system.
Code:

uname -a

which will show something like :
Code:

Linux ‘hostname’ 2.6.9-11.ELsmp #1 SMP Wed Jun 8 17:54:20 CDT 2005 i686 athlon i386 GNU/Linux

9. Now copy the config file of 2.6.9-11.ELsmp into new kernel as .config
Code:

cp /boot/config-2.6.9-11.ELsmp /usr/src/linux-2.6.15.4/.config

10. Then
Code:

make clean

11. And
Code:

make mrproper

12. And now we hit the oldconfig
Code:

make oldconfig

You will get a list of information and then it will ask you to confirm the modules.
You can just keep on hitting Enter key to set them to default BUT be carefull that you donot pass the CPU selection.
YOU WILL NEED TO SELECT THE CORRECT CPU ON YOUR SYSTEM INFORMATION WILL BE AVAILABLE IN THE /proc/cpuinfo FILE.
And also select 1 i.e : “(No Forced Preemption (server))” in the very next opition and then keep on hitting Enter again.

13. Create an Image
Code:

make bzImage

14. Unpack the modules.
Code:

make modules

15. Install the modules .
Code:

make modules_install

16. Now installing the kernel.
Code:

make install

OK.. we have finished with the intallation, now it is time to configure GRUB to pickup the new Linux kernel on reboot. Since there are always chances for kernel to fail we would set GRUP take it only once and then go back to old so that incase any thing has gone wrong we can simply reboot again to get back on the old Linux kernel.

17. So this is how we do the trick:
Code:

grub

above command will take you to grub prompt
then
Code:

grub > savedefault –default=0 –once
grub > quit

18. And finally reboot.
Code:

reboot

If every thing has gone fine then check the modules with lsmod command and confirm that they are present specially iptables.

19. Now make change in /boot/grub/grub.conf to set the new kernel as default.
Code:

pico /boot/grub/grub.conf

change
Code:

default=1

to
Code:

default=0

THATS IT… WE ARE DONE WITH KERNEL COMPILATION ON A LINUX MACHINE.

Additional Information:
————————

What is Kernel ?
A.
1. Today’s operating systems are built in “layers.” Each layer has different functions such as serial port access, disk access, memory management, and the

user interface itself. The base layer, or the foundation of the operating system, is called the kernel. The kernel provides the most basic “low-level”

services, such as the hardware-software interaction and memory management. The more efficient the kernel is, the more efficiently the operating system will run.

2. It is important for the kernel to be as small as possible while still providing all the essential services required by other parts of the operating system and applications.

Why do we need customized Linux Kernel ?
A.
It depends on exactly what does your system require and is it supported by our current kernel or not ? However you need to be a guru in Linux to have your own kernel.
What we do here is use a kernel that is already tested by others and have come up with most of the bugs in the older version and install it with the old configuration. So that keeps us on minimum risk of server getting crashed.