Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use kernel module in Linux system

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will talk to you about how to use the kernel module in the Linux system, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

1. Linux kernel design: single kernel, modularization (dynamic loading and unloading)

(1) Linux: single kernel design, but fully draws lessons from the advantages of the design of micro-kernel system; introduces a modular mechanism for the kernel.

(2) components of the kernel:

Kernel: kernel kernel, usually in bzImage format, usually located in the / boot directory, named vmlinuz-VERSION-release

The file is no longer in use after the system starts, because it has been loaded into memory and is easy to manage under / boot.

Kernel object: kernel module, usually placed in / lib/modules/VERSION-release/

The kernel module and the kernel version must match strictly

two。 Kernel modules: compilation selection mode

[]: n, do not compile this section

[M]: Module, compiled with modularization, can be temporarily loaded, takes up disk space and does not take up kernel space

[*]: y, compiled into the kernel and can be called directly

3.ramdisk: auxiliary files, not required, depending on whether the kernel can directly drive the device on which the rootfs is located

Ramdisk: a paperback version of the root file system, which provides the following drivers:

Target device driver, such as SCSI device driver

Logical device drivers, such as drivers for LVM devices

File system, such as xfs file system

Kernel module information acquisition and management commands

1.ldd: print the library files that binary applications depend on-print shared library dependencies

Format: ldd [OPTION]... FILE...

Display:

1) dependent library file name = > dependent library file path (corresponding to memory loading symbolic link mapping)

2) the entry of the entire system call library

Linux-vdso.so.1 = > (0x00007fff293fe000) / lib64/ld-linux-x86-64.so.2 (0x00007f0228073000)

2.uname: kernel information acquisition-print system information

Format: uname [OPTION]...

Uname-a: displays all kernel information

Uname-v: the compiled version number of the kernel

Uname-r: release release number of the kernel

Uname-n: host name

3.lsmod: list kernel modules

The kernel shown is from / proc/modules

Module name, size, number of times referenced, by what reference

4.modinfo command: displays the details of the specified module

Format: modinfo [- F field] [- k kernel] [modulename | filename...]

-k kernel: to query module information on another kernel when multiple cores coexist

-F field: displays only the information for the specified field

-n: show file path

Display relevant information by reading the original data of the / lib/modules/#/* file

Display content: file name, protocol, description, author, alias, RHEL version number, dependent module, signature unit, signature, encryption algorithm

5.modprobe: loads and unloads modules, and mounts dependent modules

Format: modprobe [- r] module_name

Dynamic loading of modules: modprobe module_name

Dynamic uninstall: modprobe-r module_name

Note: modules loaded by default should not be unloaded at will

6. DepmodRu-Generate modules.dep and map files

A tool for generating kernel module dependency relationship files and system information mapping files

7.insmod, rmmod: module loading and unloading, which cannot automatically resolve module dependencies

Insmod [filename] [module options...]

Filename: the file path of the module file

Rmmod [module_name]

Management of ramdisk files

1.mkinitrd (CentOS 5): recreate the ramdisk file for the kernel currently in use

# mkinitrd [OPTION...] []

The with=: needs to be loaded into the initramfs module in addition to the default module

-- the modules provided by preload=:initramfs require preloaded modules

Example: ~] # mkinitrd / boot/initramfs-$ (uname-r) .img $(uname-r)

2.dracut (CentOS 6amp 7, compatible with 5):-low-level tool for generating an initramfs image

# dracut [OPTION...] [[]]

Example: ~] # dracut / boot/initramfs-$ (uname-r) .img $(uname-r)

Kernel information output pseudo file system

1./proc: output interface for kernel status and statistics; also provides a configuration interface, / proc/sys

(1) parameters:

Read-only: information output; for example, information related to / proc/#/*, process

Writable: it is acceptable for the user to specify a "new value" to configure a function or feature of the kernel; / proc/sys/

Format: / proc/sys: net/ipv4/ip_forward is equivalent to net.ipv4.ip_forward

(2) modify the parameter mode

1) sysctl command

Designed to view or set the values of parameters in the / proc/sys directory; sysctl [options] [variable [= value]]

View: # sysctl-a * sysctl variable

Modify its value: # sysctl-w variable=value

2) File system commands (cat, echo)

View: # cat / proc/sys/PATH/TO/SOME_KERNEL_FILE

Settings: # echo "VALUE" > / proc/sys/PATH/TO/SOME_KERNEL_FILE

3) configuration file: / etc/sysctl.conf, / etc/sysctl.d/*.conf

Effective immediately: sysctl-p [/ PATH/TO/CONFIG_FILE]

(3) important kernel parameters

Net.ipv4.ip_forward: core forwarding

Vm.drop_caches:

Kernel.hostname: hostnam

Net.ipv4.icmp_echo_ignore_all: ignore all ping operations

2./sys directory: introduced after Kernel 2.6

Sys file system: outputs the relevant attribute information of each hardware device recognized by the kernel, as well as the kernel's settable parameters for hardware features.

By modifying these parameters, the working characteristics of the hardware equipment can be customized.

Udev: create device files for each hardware device on demand by reading the hardware device information in the / sys directory

Udev is a user space program; special tools: devadmin, hotplug

When udev creates a device file for a device, it reads its pre-defined rule file

Generally under the / etc/udev/rules.d/ directory and / usr/lib/udev/rules.d/ directory

After reading the above, do you have any further understanding of how the kernel module is used in Linux systems? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report