Wise people learn when they can; fools learn when they must - Arthur Wellesley

Sunday, 9 April 2017

RHEL6-22-LINUX KERNEL -1


RHEL6-22-LINUX KERNEL -1

THE LINUX KERNEL:


The kernel is the central module of an operating system (OS). It is the part of the operating system that loads first, and it remains in main memory. Because it stays in memory, 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. The kernel code is usually loaded into a protected area of memory to prevent it from being overwritten by programs or other parts of the operating system.
Typically, the kernel is responsible for memory management, process and task management, and disk management. The kernel connects the system hardware to the application software. Every operating system has a kernel. For example the Linux kernel is used numerous operating systems including Linux, FreeBSD, Android and others.


From “howtogeek.com”

Different Types of Kernels:

Most kernels fall into one of three types: monolithic, microkernel, and hybrid. Linux is a monolithic kernel while OS X (XNU) and Windows 7 use hybrid kernels.

Microkernel:
A microkernel takes the approach of only managing what it has to: CPU, memory, and IPC. Pretty much everything else in a computer can be seen as an accessory and can be handled in user mode.

Monolithic Kernel:
Monolithic kernels are the opposite of microkernels because they encompass not only the CPU, memory, and IPC, but they also include things like device drivers, file system management, and system server calls. Monolithic kernels tend to be better at accessing hardware and multitasking because if a program needs to get information from memory or another process running it has a more direct line to access it and doesn’t have to wait in a queue to get things done.

Hybrid Kernel:
Hybrid kernels have the ability to pick and choose what they want to run in user mode and what they want to run in supervisor mode. Often times things like device drivers and filesystem I/O will be run in user mode while IPC and server calls will be kept in the supervisor mode.

=======================XX=============XX=============XX===================

The kernel can be used to load new drivers, supports new hardware modules, and even allow us to compile it as per requirement. Kernel is module based, means we can load/unload the modules.

Commands to interact with kernel.

uname      To get info about the kernel
lsmod      To get info about currently loaded kernel modules
lspci      To get info about currently loaded kernel modules
modinfo    To get info about a kernel module
sysctl     Enables us to tune kernel parameters
dmesg      To get current kernel messages
modprobe   To load a kernel module
modinfo <module Name> To get the info about particular module

How to know what version of kernel is installed?

[root@rhel6-client1 ~]# rpm -qa |grep -i kernel*
libreport-plugin-kerneloops-2.0.9-15.el6.x86_64
kernel-firmware-2.6.32-358.el6.noarch
kernel-2.6.32-358.el6.x86_64
abrt-addon-kerneloops-2.0.8-15.el6.x86_64
dracut-kernel-004-303.el6.noarch

[root@rhel6-client1 ~]# uname -a
Linux rhel6-client1 2.6.32-358.el6.x86_64 #1 SMP Tue Jan 29 11:47:41 EST 2013 x86_64 x86_64 x86_64 GNU/Linux

[root@rhel6-client1 ~]# uname -r
2.6.32-358.el6.x86_64

Our kernel version is “2.6.32-358.el6.x86_64”

[root@rhel6-client1 ~]# yum info kernel
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
localrepo                                                                                                      | 2.9 kB     00:00 ...
Installed Packages
Name        : kernel
Arch        : x86_64
Version     : 2.6.32
Release     : 358.el6
Size        : 116 M
Repo        : installed
From repo   : anaconda-RedHatEnterpriseLinux-201301301459.x86_64
Summary     : The Linux kernel
URL         : http://www.kernel.org/
License     : GPLv2
Description : The kernel package contains the Linux kernel (vmlinuz), the core of any
            : Linux operating system.  The kernel handles the basic functions
            : of the operating system: memory allocation, process allocation, device
            : input and output, etc.

How do I know that installed kernel is stable or unstable kernel version?

By looking at 2nd no. if the second no is “even” then it is stable. Incase if it is “odd” then the kernel is unstable (kernel under development).

Here it is 2.6.32 means stable b’coz of even no.

What is the release version of kernel?

“2.6.32-358.el6.x86_64”

2      (1st)          is the major release version.
6      (2nd)          is minor release of major version.
32     (3rd)          is patch version/revision no of kernel.
el6    (4th)          means it is rhel6
x86_64 (5th)          is denoting that it is X64 version of OS

Where kernel is residing?

[root@rhel6-client1 ~]# ls -l /boot/vmlinuz*
-rwxr-xr-x. 1 root root 4044560 Jan 29  2013 /boot/vmlinuz-2.6.32-358.el6.x86_64

vmlinux   An uncompressed version of the Linux kernel file; usually generated as
an intermediate step and not copied to /boot . This form of the kernel is
not directly bootable, since it ’  s missing a few features.

vmlinuz   A variant of vmlinux that’s been compressed with any of several tools and rendered bootable by adding some features. Linux distribution providers
typically use vmlinuz as the name for their precompiled binary kernels.

Where the kernel modules are residing?

[root@rhel6-client1 ~]# ls -l /lib/modules/
total 4
drwxr-xr-x. 8 root root 4096 Feb 15 01:14 2.6.32-358.el6.x86_64

[root@rhel6-client1 ~]# ls -l /lib/modules/2.6.32-358.el6.x86_64/
total 3420
lrwxrwxrwx.  1 root root     46 Feb 14 23:39 build -> ../../../usr/src/kernels/2.6.32-358.el6.x86_64
drwxr-xr-x.  2 root root   4096 Jan 29  2013 extra
drwxr-xr-x. 11 root root   4096 Feb 14 23:40 kernel
drwxr-xr-x.  2 root root   4096 Feb 15 01:13 misc
-rw-r--r--.  1 root root 567161 Feb 15 01:14 modules.alias
-rw-r--r--.  1 root root 546398 Feb 15 01:14 modules.alias.bin
-rw-r--r--.  1 root root   1369 Jan 29  2013 modules.block
-rw-r--r--.  1 root root     69 Feb 15 01:14 modules.ccwmap
-rw-r--r--.  1 root root 196886 Feb 15 01:14 modules.dep
-rw-r--r--.  1 root root 287344 Feb 15 01:14 modules.dep.bin
-rw-r--r--.  1 root root     68 Jan 29  2013 modules.drm
-rw-r--r--.  1 root root    665 Feb 15 01:14 modules.ieee1394map
-rw-r--r--.  1 root root    141 Feb 15 01:14 modules.inputmap
-rw-r--r--.  1 root root   1236 Feb 15 01:14 modules.isapnpmap
-rw-r--r--.  1 root root     29 Jan 29  2013 modules.modesetting
-rw-r--r--.  1 root root   1905 Jan 29  2013 modules.networking
-rw-r--r--.  1 root root     74 Feb 15 01:14 modules.ofmap
-rw-r--r--.  1 root root  74887 Jan 29  2013 modules.order
-rw-r--r--.  1 root root 405413 Feb 15 01:14 modules.pcimap
-rw-r--r--.  1 root root   6259 Feb 15 01:14 modules.seriomap
-rw-r--r--.  1 root root 217112 Feb 15 01:14 modules.symbols
-rw-r--r--.  1 root root 275906 Feb 15 01:14 modules.symbols.bin
-rw-r--r--.  1 root root 837314 Feb 15 01:14 modules.usbmap
lrwxrwxrwx.  1 root root      5 Feb 14 23:40 source -> build
drwxr-xr-x.  2 root root   4096 Jan 29  2013 updates
drwxr-xr-x.  2 root root   4096 Feb 14 23:40 vdso
drwxr-xr-x.  2 root root   4096 Jan 29  2013 weak-updates


From where the OS refer kernel to boot the system?

[root@rhel6-client1 ~]# cat /boot/grub/grub.conf
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/sda6
#          initrd /initrd-[generic-]version.img
#boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux (2.6.32-358.el6.x86_64)
        root (hd0,0)
        kernel /vmlinuz-2.6.32-358.el6.x86_64 ro root=UUID=a05fc3a5-ce73-4940-be2d-4a9c3a67e6b5 rd_NO_LUKS rd_NO_LVM LANG=en_US.UTF-8 rd_NO_MD SYSFONT=latarcyrheb-sun16 crashkernel=auto  KEYBOARDTYPE=pc KEYTABLE=us rd_NO_DM rhgb quiet
        initrd /initramfs-2.6.32-358.el6.x86_64.img

How to find out the currently loaded kernel modules?

[root@rhel6-client1 ~]# lsmod
Module                  Size  Used by
dm_snapshot            31105  3
dm_log_userspace       10933  0
rfcomm                 74055  4
sco                    18005  2
bridge                 79078  0
bnep                   16690  2
l2cap                  55682  16 rfcomm,bnep
autofs4                26513  3
llc                     5546  3 bridge,garp,stp
======================O/P REMOVED=================================

Module column specifies the names of all the modules that are currently loaded.
Used by column specifies what’s using the module. All the entries have a number, which indicates the number of other modules or processes that are using the module. Like, “dm_log_userspace” and “bridge” having used by value is 0, means they are not used by any other modules or simply they are unused.
Again module “llc’ is used by 3 modules “bridge,garp,stp”.

So what if I have to remove “dm_log_userspace” and “bridge” modules?

[root@rhel6-client1 ~]# lsmod |egrep "bridge|dm_log_userspace"
dm_log_userspace       10933  0
bridge                 79078  0
stp                     2218  2 bridge,garp
llc                     5546  3 bridge,garp,stp
dm_log                  9930  3 dm_log_userspace,dm_mirror,dm_region_hash
dm_mod                 82839  29 dm_snapshot,dm_log_userspace,dm_mirror,dm_log

We can remove them directly, b’coz they are not using any module as having “Used by” value is 0.

But what if I want to remove “stp,llc,dm_log,dm,mod” modules?

We cannot remove them bluntly; first we need to remove the dependents then only we can remove them.  

How to get the info about particular kernel module?

[root@rhel6-client1 ~]# modinfo bluetooth
filename:       /lib/modules/2.6.32-358.el6.x86_64/kernel/net/bluetooth/bluetooth.ko
alias:          net-pf-31
license:        GPL
version:        2.15
description:    Bluetooth Core ver 2.15
author:         Marcel Holtmann <marcel@holtmann.org>
srcversion:     6A619863886C20825D5C042
depends:        rfkill
vermagic:       2.6.32-358.el6.x86_64 SMP mod_unload modversions

[root@rhel6-client1 ~]# modinfo vmhgfs
filename:       /lib/modules/2.6.32-358.el6.x86_64/misc/vmhgfs.ko
supported:      external
alias:          vmware_vmhgfs
license:        GPL v2
version:        1.4.1.1
description:    VMware Host/Guest File System
author:         VMware, Inc.
depends:        vmci
vermagic:       2.6.32-131.0.15.el6.x86_64 SMP mod_unload modversions
parm:           USE_VMCI:int
parm:           HOST_IP:charp
parm:           HOST_PORT:int
parm:           HOST_VSOCKET_PORT:int
[root@rhel6-client1 ~]#

[root@rhel6-client1 ~]# modinfo -F description vmhgfs
VMware Host/Guest File System
[root@rhel6-client1 ~]# modinfo -F filename vmhgfs
/lib/modules/2.6.32-358.el6.x86_64/misc/vmhgfs.ko

How to know that kernel has initialized a new device or not?

[root@rhel6-client1 ~]# dmesg |grep -i usb

How to tune the kernel parameters temporarily?

The kernel has a virtual file system, /proc/sys, that allows you to tune the kernel while the system is running
The kernel creates the /proc/sys virtual file system when the system boots up, which holds all the parameters of the kernel.
We can tune the kernel parameters by altering /proc/sys/<…………>, but these changes are temporary and will vanish after system reboot.
So it is better for testing purpose.

[root@rhel6-client1 ~]# ls -l /proc/sys/kernel
total 0
-rw-r--r-- 1 root root 0 Apr  8 15:00 acct
-rw-r--r-- 1 root root 0 Apr  8 15:00 acpi_video_flags
-rw-r--r-- 1 root root 0 Apr  8 15:00 auto_msgmni
-rw-r--r-- 1 root root 0 Apr  8 15:00 blk_iopoll
-r--r--r-- 1 root root 0 Apr  8 15:00 bootloader_type
-r--r--r-- 1 root root 0 Apr  8 15:00 bootloader_version
-rw------- 1 root root 0 Apr  8 15:00 cad_pid
-rw-r--r-- 1 root root 0 Apr  8 15:00 compat-log
-rw-r--r-- 1 root root 0 Mar 31 12:23 core_pattern
======================O/P REMOVED=================================

[root@rhel6-client1 ~]# cat /proc/sys/kernel/osrelease
2.6.32-358.el6.x86_64

[root@rhel6-client1 ~]# cat /proc/sys/kernel/panic
0

[root@rhel6-client1 ~]# cat /proc/sys/kernel/version
#1 SMP Tue Jan 29 11:47:41 EST 2013

[root@rhel6-client1 ~]# cat /proc/sys/kernel/pid_max
32768

Changing kernel parameter temporarily.

[root@rhel6-client1 ~]# cat /proc/sys/fs/file-max
188006

[root@rhel6-client1 ~]# echo 250000 > /proc/sys/fs/file-max

[root@rhel6-client1 ~]# cat /proc/sys/fs/file-max
250000

[root@rhel6-client1 ~]# sysctl -a |grep file-max
fs.file-max = 250000

This value will roll back after reboot.

[root@rhel6-client1 ~]# reboot

Broadcast message from root@rhel6-client1
        (/dev/pts/1) at 10:29 ...

The system is going down for reboot NOW!
[root@rhel6-client1 ~]#

[root@rhel6-client1 ~]# sysctl -a |grep file-max
fs.file-max = 188006


Reference for kernel theory:



No comments:

Post a Comment