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 learn more about Linux kernel module

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article is about how to learn the Linux kernel module in depth. The editor thinks it is very practical, so I hope you can get something after reading this article. Let's take a look at it with the editor.

The lsmod command tells you which kernel modules are currently loaded on your system, as well as some interesting details about using them.

What is a Linux kernel module?

Kernel modules are blocks of code that can be loaded into or unloaded from the kernel as needed, so kernel functionality can be extended without rebooting. In fact, unless the user uses a command like lsmod to query module information, the user is unlikely to know about any changes to the kernel.

The important thing to know is that there will always be a lot of modules available on your Linux system, and if you can dig into them, you can learn a lot of details.

One of the main uses of lsmod is to check the module when the system is not working properly. In most cases, however, modules are loaded as needed, and users don't need to know how they work.

Display kernel module

The easiest way to display kernel modules is to use the lsmod command. Although this command contains a lot of details, the output is very user-friendly.

$lsmodModule Size Used bysnd_hda_codec_realtek 114688 1snd_hda_codec_generic 77824 1sndroomhdaq codecs _ realtekledtrig_audio 16384 2snd_hda_codec _ generic,snd_hda_codec_realteksnd_hda_codec_hdmi 53248 1snd_hda_intel 40960 2snd_hda_codec 131072 4 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel Snd_hda_codec_realteksnd_hda_core 86016 5 snd_hda_codec_generic,snd_hda_codec_hdmi,snd_hda_intel, snd_hda_codec,snd_hda_codec_realteksnd_hwdep 20480 1 snd_hda_codecsnd_pcm 102400 4 snd_hda_codec_hdmi,snd_hda_intel,snd_hda_codec Snd_hda _ coresnd_seq_midi 20480 0snd_seq_midi_event 16384 1 snd_seq_mididcdbas 20480 0snd_rawmidi 36864 1 snd_seq_midisnd_seq 69632 2 snd_seq_midi,snd_seq_midi_eventcoretemp 20480 0snd_seq_device 16384 3 snd_seq,snd_seq_midi Snd_rawmidisnd_timer 36864 2 snd_seq,snd_pcmkvm_intel 241664 0kvm 626688 1 kvm_intelradeon 1454080 10irqbypass 16384 1 kvmjoydev 24576 0input_leds 16384 0ttm 102400 1 radeondrm_kms_helper 180224 1 radeondrm 475136 13 drm_kms_helper,radeon Ttmsnd 81920 15 snd_hda_codec_generic,snd_seq,snd_seq_device,snd_hda _ codec_hdmi,snd_hwdep,snd_hda_intel,snd_hda_codec,snd _ hda_codec_realtek,snd_timer,snd_pcm Snd_rawmidii2c_algo_bit 16384 1 radeonfb_sys_fops 16384 1 drm_kms_helpersyscopyarea 16384 1 drm_kms_helperserio_raw 20480 0sysfillrect 16384 1 drm_kms_helpersysimgblt 16384 1 drm_kms_helpersoundcore 16384 1 sndmac_hid 16384 0sch_fq_codel 20480 2parport_pc 40960 0ppdev 24576 0lp 20480 0parport 53248 3 parport_pc Lp,ppdevip_tables 28672 0x_tables 40960 1 ip_tablesautofs4 45056 2raid10 57344 0raid456 155648 0async_raid6_recov 24576 1 raid456async_memcpy 20480 2 raid456,async_raid6_recovasync_pq 24576 2 raid456,async_raid6_recovasync_xor 20480 3 async_pq,raid456 Async_raid6_recovasync_tx 20480 5 async_pq,async_memcpy,async_xor,raid456,async_raid6_re covxor 24576 1 async_xorraid6_pq 114688 3 async_pq,raid456 Async_raid6_recovlibcrc32c 16384 1 raid456raid1 45056 0raid0 24576 0multipath 20480 0linear 20480 0hid_generic 16384 0psmouse 151552 0i2c_i801 32768 0pata_acpi 16384 0lpc_ich 24576 0usbhid 53248 0hid 126976 2 usbhid Hid_generice1000e 245760 0floppy 81920 0

In the output above:

Module displays the name of each module

Size shows the size of each module (not the amount of memory they occupy)

Used by displays the number of times each module is used and the modules that use them

Obviously, there are many modules here. The number of modules loaded depends on your system and version, as well as what is running. We can count like this:

$lsmod | wc-L67

To see the number of modules available in the system (not just running), try this command:

$modprobe-c | wc-l41272 other commands related to kernel modules

Linux provides several commands for listing, loading and unloading, testing, and checking the status of modules.

Depmod-generate modules.dep and mapping files

Insmod-A program that inserts modules into the Linux kernel

Lsmod-displays the status of modules in the Linux kernel

Modinfo-displays Linux kernel module information

Modprobe-add or remove Linux kernel modules

Rmmod-A program that removes modules from the Linux kernel

Show built-in kernel modules

As mentioned earlier, the lsmod command is the most convenient command to display kernel modules. However, there are other ways to display them. All modules built in the kernel are listed in the modules.builtin file and are used when the modprobe command attempts to add modules in the file. Note that the $(uname-r) in the following command provides the name of the kernel version.

$more / lib/modules/$ (uname-r) / modules.builtin | head-10kernel/arch/x86/crypto/crc32c-intel.kokernel/arch/x86/events/intel/intel-uncore.kokernel/arch/x86/platform/intel/iosf_mbi.kokernel/mm/zpool.kokernel/mm/zbud.kokernel/mm/zsmalloc.kokernel/fs/binfmt_script.kokernel/fs/mbcache.kokernel/fs/configfs/configfs.kokernel/fs/crypto/fscrypto.ko

You can use modinfo to get more details about a module, although there is no simple description of the services provided by the module. The lengthy signature is omitted in the output below.

$modinfo floppy | head-16filename: / lib/modules/5.0.0-13-generic/kernel/drivers/block/floppy.koalias: block-major-2-*license: GPLauthor: Alain L. Knaffsrcversion: EBEAA26742DF61790588FD9alias: acpi*:PNP0700:*alias: pnp:dPNP0700*depends:retpoline: Yintree: Yname: floppyvermagic: 5.0 .0-13-generic SMP mod_unloadsig_id: PKCS#7signer:sig_key:sig_hashalgo: md4

You can use the modprobe command to load or unload modules. Using the following command, you can find the kernel object associated with a particular module:

$find / lib/modules/$ (uname-r)-name floppy*/lib/modules/5.0.0-13-generic/kernel/drivers/block/floppy.ko

If you want to load the module, you can use this command:

$sudo modprobe floppy

Obviously, the loading and unloading of kernel modules is very important. It makes Linux systems more flexible and efficient than when running with a general-purpose kernel. This also means that you can make major changes without rebooting, such as adding hardware.

The above is how to in-depth study of the Linux kernel module, the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.

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