Linux Kernel Basics

Source: Internet
Author: User
Tags andrew morton dmesg

Linux kernel functions:

The Linux kernel is the heart of the operating system. It's the layer between the user who works with Linux from a shell environment and the hardware that's available in the C Omputer on which the user is working. The kernel is doing so by managing the I/O instructions it receives from the software and translating those to processing Instructions that is to being executed by the central processing Unit and other hardware in the computer. The kernel also takes care of handling essential operating system tasks. One example of such a task is the scheduler, makes sure that processes that was started on the operating system was H Andled by the CPU. The operating system tasks is performed by the kernel is implemented by different kernel threads.

To view the system kernel process:

[[email protected] ~]# PS aux |        Head-n 20USER PID%cpu%MEM VSZ RSS TTY STAT START time commandroot 1 0.0 0.3 126560 7264?      Ss 02:23 0:04/usr/lib/systemd/systemd--switched-root--system--deserialize 20root 2 0.0 0.0 0        0?        S 02:23 0:00 [kthreadd]root 3 0.0 0.0 0 0?        S 02:23 0:00 [ksoftirqd/0]root 5 0.0 0.0 0 0?        s< 02:23 0:00 [kworker/0:0h]root 7 0.0 0.0 0 0?        S 02:23 0:00 [migration/0]root 8 0.0 0.0 0 0?        S 02:23 0:00 [rcu_bh]root 9 0.0 0.0 0 0?        S 02:23 0:00 [rcuob/0]root 10 0.0 0.0 0 0?        S 02:23 0:00 [rcuob/1]root 11 0.0 0.0 0 0?        S 02:23 0:01 [rcu_sched]root 12 0.0 0.0 0 0?        S 02:23 0:00 [rcuos/0]root 13 0.0 0.0 0 0? S 02:23 0:01 [Rcuos/1]root 14 0.0 0.0 0 0?        S 02:23 0:00 [watchdog/0]root 15 0.0 0.0 0 0?        S 02:23 0:00 [watchdog/1]root 16 0.0 0.0 0 0?        S 02:23 0:00 [migration/1]root 17 0.0 0.0 0 0?        S 02:23 0:00 [ksoftirqd/1]root 19 0.0 0.0 0 0?        s< 02:23 0:00 [kworker/1:0h]root 20 0.0 0.0 0 0?        s< 02:23 0:00 [khelper]root 21 0.0 0.0 0 0?        S 02:23 0:00 [kdevtmpfs]root 22 0.0 0.0 0 0? s< 02:23 0:00 [Netns]

The kernel thread names is listed between square brackets.

    • Hardware Initialization--a key task of the kernel is hardware initialization

The loading of drivers is a automated process that roughly goes like this:
1. During boot, the kernel probes avail Able Hardware.
2. Upon detection of a hardware component, the SYSTEMD-UDEVD process takes care of loading the appropriate driver and Making the hardware device available.
3. To decide how the devices is initialized, SYSTEMD-UDEVD reads rules files IN/USR/LIB/UDEV/RULES.D. These is system provided udev rules files, should not being modified.
4. After processing the system provided UDEV rules files, SYSTEMD-UDEVD goes to the/etc/udev/rules.d directory to Rea D any custom rules if these is available.
5. As a result, required kernel modules is loaded automatically and status about the kernel modules and associated ha Rdware is written to the Sysfs file system which are mounted on The/sys directory.

[[email protected] rules.d]# udevadm monitormonitor would print the Received events For:udev-the event which UDEV sends out after rule processingkernel-the kernel ueventkernel[26762.7207 CHANGE/DEVICES/PCI0000:00/0000:00:01.1/ATA2/HOST1/TARGET1:0:0/1:0:0:0/BLOCK/SR0 (block)-mount CD-ROM Udev [ 26762.780435] CHANGE/DEVICES/PCI0000:00/0000:00:01.1/ATA2/HOST1/TARGET1:0:0/1:0:0:0/BLOCK/SR0 (block) KERNEL[ 26781.664833] CHANGE/DEVICES/PCI0000:00/0000:00:01.1/ATA2/HOST1/TARGET1:0:0/1:0:0:0/BLOCK/SR0 (block)-unmount CD-ROM Udev [ 26781.767169] CHANGE/DEVICES/PCI0000:00/0000:00:01.1/ATA2/HOST1/TARGET1:0:0/1:0:0:0/BLOCK/SR0 (block) 

In this command, you can see how features is offered by the hardware is discovered automatically by the kernel and Udev working together. Each phase of the hardware probing are concluded by the creation of a file in The/sys file system. Once the hardware have been fully initialized, you can also see that some kernel modules is loaded.

    • Analyzing what's the Kernel is Doing-- See what the kernel is doing

To help analyze-the kernel is doing, some tools be provided by the Linux operating systems:
The DMESG utility--journalctl--DMESG or Journalctl-k
The/proc File System
The uname utility

[[email protected] ~]# journalctl--dmesg--Logs begin at Sat 2016-08-13 02:23:44 EDT, end at Sat 2016-08-13 10:01:01 EDT. --aug 02:23:44 localhost.localdomain kernel:initializing cgroup subsys Cpusetaug all 02:23:44 localhost.localdomain ker Nel:initializing cgroup subsys Cpuaug 02:23:44 localhost.localdomain kernel:initializing cgroup Subsys cpuacctAug 13 02:23:44 localhost.localdomain kernel:linux version 3.10.0-327.el7.x86_64 ([email protected]) (GCC versioAug 13 02 : 23:44 localhost.localdomain Kernel:command line:boot_image=/vmlinuz-3.10.0-327.el7.x86_64 root=/dev/mapper/ Rhel-root ro Crashkaug 02:23:44 localhost.localdomain kernel:e820:bios-provided physical RAM map:Aug 02:23:44 Loca Lhost.localdomain kernel:bios-e820: [Mem 0x0000000000000000-0x000000000009fbff] Usableaug 13 02:23:44 Localhost.localdomain kernel:bios-e820: [Mem 0x000000000009fc00-0x000000000009ffff] Reservedaug 13 02:23:44 Localhost.localdomain kernel:bios-e820: [Mem 0x00000000000f0000-0X00000000000FFFFF] Reservedaug 02:23:44 localhost.localdomain kernel:bios-e820: [Mem 0X0000000000100000-0X000000007FFEFFFF] Usableaug 02:23:44 localhost.localdomain kernel:bios-e820: [Mem 0X000000007FFF0000-0X000000007FFFFFFF] ACPI Dataaug 02:23:44 localhost.localdomain kernel:bios-e820: [Mem 0X00000000FFFC0000-0X00000000FFFFFFFF] Reservedaug 02:23:44 localhost.localdomain kernel:nx (Execute Disable) Protection:activeaug 02:23:44 localhost.localdomain Kernel:smbios 2.5 present. 02:23:44 localhost.localdomain Kernel:DMI:innotek GmbH virtualbox/virtualbox, BIOS VirtualBox 12/01/2006aug 13 02 : 23:44 localhost.localdomain kernel:e820:update [mem 0x00000000-0x00000fff] usable ==> reserved

In the DMESG output, all kernel-related messages is shown. Each message starts with a time indicator this shows at which specific second the event was logged. This time indicator was relative to the start of the kernel, which allows what do I see exactly what many seconds has passed B Etween the start of the kernel and a particular event. (Notice that the journalctl-k/--DMESG commands show clock time, instead of time that's relative to the start of the Kernel.) This time indicator gives a clear indication of what have been happening and at which time it has happened.

Another valuable source of information is The/proc file system. The/proc file system is a interface to the Linux kernel, and it contains files with detailed actual status information o n What's happening on your server. Many of the Performancerelated tools mine The/proc file system for more information.

As an administrator, you'll find that some of the files In/proc is very readable and contain actual status information About CPUs, memory, mounts, and more. Take a look, for instance, At/proc/meminfo, which gives detailed information on each memory segment and what exactly I s happening in these memory segments.

A last useful source of information This should be mentioned this is the uname command. This command gives different kinds of the information about your operating system. Type, for instance, uname-a for a overview of all relevant parameters of uname-r to see which kernel version Curren Tly is used. This information also shows when using the Hostnamectl status command.

    • managing Kernel Modules --Managing kernel modules

Linux kernel modules normally is loaded automatically for the devices so need them, but you'll sometimes has to load The appropriate kernel modules manually.  A few commands is used for manual management of kernel modules. An alternative method of loading kernel modules are by doing this through THE/ETC/MODULES-LOAD.D directory. In this directory, you can create files to load modules automatically that is not a loaded by the Udev method already.

The first command to use when working with kernel modules is lsmod. This command lists all kernel modules that currently be used, including the modules by which this specific module is used .

If you want to has more information on a specific kernel module, you can use the  modinfo  command. This gives complete information about the specific kernel modules, including, interesting sections:the alias and the P Arms. A Module alias is another name, can also be used to address the module. The parms lines refer to parameters the can is set while loading the module. 

[Email protected] ~]# modinfo cdromfilename:       /lib/modules/3.10.0-327.el7.x86_64/kernel/drivers/cdrom/ Cdrom.kolicense:        gplrhelversion:    7.2srcversion:     be3bd0d17d080229d55b173depends:        intree:         Yvermagic:       3.10.0-327.el7.x86_64 SMP mod_unload modversions signer:         Red Hat Enterprise Linux kernel signing Keysig_key:        Bc:73:c3:ce:e8:9e:5e:ae:99:4a:e5:0a:0d:b1:f0:fe:e3:fc:09:13sig_hashalgo:   sha256parm:           Debug:boolparm:           autoclose:boolparm:           autoeject:boolparm:           lockdoor:boolparm:           Check_media_ Type:boolparm:           Mrw_format_restart:bool

To manually load and unload modules, you can use the Modprobe and Modprobe-r commands.

[[email protected] ~]# lsmod | grep ext4[[email protected] ~]# modprobe ext4[[email protected] ~]# lsmod | grep ext4ext4 578819 0 mbcache 14958 1 ext4jbd2 102940 1 EXT4[[EMAIL&N Bsp;protected] ~]# modinfo ext4filename:/LIB/MODULES/3.10.0-327.EL7.X86_64/KERNEL/FS/EXT4/EXT4.KOLICENSE:GP Ldescription:fourth Extended filesystemauthor:remy Card, Stephen Tweedie, Andrew Morton, Andreas Dilger, Theo          Dore Ts ' O and Othersalias:fs-ext4alias:ext3alias:fs-ext3alias:ext2alias:       Fs-ext2rhelversion:7.2srcversion:db48bdadd011de28724eb21depends:mbcache,jbd2intree:yvermagic:        3.10.0-327.el7.x86_64 SMP mod_unload modversions signer:red Hat Enterprise Linux kernel signing Keysig_key: Bc:73:c3:ce:e8:9e:5e:ae:99:4a:e5:0a:0d:b1:f0:fe:e3:fc:09:13sig_hashalgo:sha256[[email protected] ~]# Modpro E-r Ext4-bash:modproe:Command not found[[email protected] ~]# modprobe-r ext4[[email protected] ~]# modprobe-r xfsmodprobe:fatal:m Odule XFS is in use.        [[email protected] ~]# modinfo xfsfilename:/lib/modules/3.10.0-327.el7.x86_64/kernel/fs/xfs/xfs.kolicense: Gpldescription:sgi XFS with ACLs, security attributes, no debug Enabledauthor:silicon Graphics, Inc.alias : Fs-xfsrhelversion:7.2srcversion:978077fbdf054363971a9eedepends:libcrc32cintree:yverma gic:3.10.0-327.el7.x86_64 SMP mod_unload modversions signer:red Hat Enterprise Linux kernel signing Keysig  _key:bc:73:c3:ce:e8:9e:5e:ae:99:4a:e5:0a:0d:b1:f0:fe:e3:fc:09:13sig_hashalgo:sha256[[email protected] ~]#
    • upgrading the Linux Kernel --linux kernel upgrade

From time to time, you need to upgrade the Linux kernel. When you upgrade the Linux kernel, a new version of the kernel is installed and used as the default kernel. The old version of the kernel file would still be available, though. This ensures, your computer can still boot if in the new kernel nonsupported functionality is included. To install a new version of the kernel, you can use the command Yum upgrade kernel . The yum install kernel command also works.   Both commands install the new kernel besides the old kernel. The kernel files for the last four kernels so you had installed on your server would be kept in The/boot directory. The GRUB 2 boot loader automatically picks up all kernels that it finds in this directory.

Linux Kernel Basics

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.