Become a kernel module guru

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
3,490
Reaction score
3,224
Credits
31,265
LKMs are object files containing code that extends the running kernel. They’re commonly used to add support for new hardware, filesystems, NICs, and more. Most often, LKMs serve as device drivers, but they can also be used for other purposes like file systems and firewalls.

To load a kernel module automatically during boot, you can edit the /etc/modules file or create a new config file in /etc/modules-load.d/.
Example: If you want to load the ide-cd and ide-core modules, add these lines to /etc/modules

Code:
ide-cd
ide-core

After editing, reboot your system to test the changes.

Use ls /usr/lib/modules/$(uname -r)/kernel/ to find the location of your Linux kernel device drivers/modules.

To load a module without rebooting, use insmod followed by the module name (e.g., insmod hello.ko).
Example: insmod /lib/modules/4.4.0-21-generic/kernel/drivers/cpufreq/speedstep-lib.ko

To remove a loaded module, use rmmod followed by the module name (e.g., rmmod hello.ko).

$ lsmod
This command will display a nicely formatted output showing the module names, their sizes, and usage information. If you need more details about a specific module, you can also use the modinfo command.

modinfo command in Linux serves the purpose of providing detailed information about a kernel module (loadable kernel object). When you run:

$ modinfo <module_name>
It displays essential details about the specified module, including:

Module name
Author(s)
Description
License
Parameters (if any)
Dependencies
Module version
Firmware (if applicable)

======================================================================
 


Akmods:
Purpose: Akmods is the Fedora/Red Hat way of managing kernel modules.
Functionality:
It automatically rebuilds kernel modules (kmods) for the running kernel.
When a new kernel is installed, akmods checks if the corresponding kmod is present.
If not found, it rebuilds the kmod from the source RPM (kmod-srpm) and installs it.

Benefit:
Simplifies maintaining kmod spec files for both the repository build system and client systems.
Similar to dkms but tailored for Fedora/RHEL systems.

Dkms (for comparison):
Purpose: Dkms is the Ubuntu way of managing kernel modules.
Functionality:
It dynamically rebuilds kernel modules when a new kernel is installed.
Ensures compatibility with the latest kernel versions.
Commonly used for third-party modules like Nvidia drivers.
Usage:
Install dkms packages for specific modules (e.g., sudo apt install nvidia-dkms).
Dkms will automatically rebuild the module during kernel updates.

Akmods are particularly useful if you are using a rolling distro like Fedora. The kernel can be updated every week when use Fedora. So how do you make sure that your nvidia video driver will work with your new kernel? You recompile it on the fly using source from your newest kernel version.
 
lsmod can return quite a long list.

lsmod
Module Size Used by
nft_fib_inet 12288 1
nft_fib_ipv4 12288 1 nft_fib_inet
nft_fib_ipv6 12288 1 nft_fib_inet
nft_fib 12288 3 nft_fib_ipv6,nft_fib_ipv4,nft_fib_inet
nft_reject_inet 12288 10
nf_reject_ipv4 12288 1 nft_reject_inet
nf_reject_ipv6 20480 1 nft_reject_inet
nft_reject 12288 1 nft_reject_inet
nft_ct 28672 7
nft_chain_nat 12288 3
nf_nat 65536 1 nft_chain_nat
nf_conntrack 192512 2 nf_nat,nft_ct
nf_defrag_ipv6 24576 1 nf_conntrack
nf_defrag_ipv4 12288 1 nf_conntrack
ip_set 69632 0
nf_tables 409600 273 nft_ct,nft_reject_inet,nft_fib_ipv6,nft_fib_ip v4,nft_chain_nat,nft_reject,nft_fib,nft_fib_inet
qrtr 57344 2
bnep 36864 2
sunrpc 905216 1
snd_sof_pci_intel_skl 12288 0
snd_sof_intel_hda_common 270336 1 snd_sof_pci_intel_skl
soundwire_intel 86016 1 snd_sof_intel_hda_common
snd_sof_intel_hda_mlink 36864 2 soundwire_intel,snd_sof_intel_hda_common
soundwire_cadence 49152 1 soundwire_intel
snd_sof_intel_hda 20480 1 snd_sof_intel_hda_common
snd_sof_pci 24576 2 snd_sof_intel_hda_common,snd_sof_pci_intel_skl
snd_sof_xtensa_dsp 16384 1 snd_sof_intel_hda_common
snd_sof 483328 3 snd_sof_pci,snd_sof_intel_hda_common,snd_sof_int el_hda
snd_sof_utils 16384 1 snd_sof
soundwire_generic_allocation 12288 1 soundwire_intel
soundwire_bus 143360 3 soundwire_intel,soundwire_generic_allocation,sou ndwire_cadence
snd_soc_avs 241664 0
snd_soc_hda_codec 28672 1 snd_soc_avs
snd_soc_skl 258048 0
snd_soc_hdac_hda 28672 2 snd_sof_intel_hda_common,snd_soc_skl
snd_hda_ext_core 36864 7 snd_soc_avs,snd_soc_hda_codec,snd_sof_intel_hda_ common,snd_soc_hdac_hda,snd_sof_intel_hda_mlink,snd_soc_skl,snd_sof_intel_hda
snd_soc_sst_ipc 16384 1 snd_soc_skl
snd_soc_sst_dsp 40960 1 snd_soc_skl
snd_soc_acpi_intel_match 98304 3 snd_sof_intel_hda_common,snd_soc_skl,snd_so f_pci_intel_skl
snd_soc_acpi 16384 3 snd_soc_acpi_intel_match,snd_sof_intel_hda_commo n,snd_soc_skl
intel_rapl_msr 20480 0
binfmt_misc 28672 1
intel_rapl_common 45056 1 intel_rapl_msr
snd_soc_core 516096 7 snd_soc_avs,snd_soc_hda_codec,soundwire_intel,sn d_sof,snd_sof_intel_hda_common,snd_soc_hdac_hda,snd_soc_skl
intel_uncore_frequency 12288 0
intel_uncore_frequency_common 16384 1 intel_uncore_frequency
snd_hda_codec_hdmi 102400 1
intel_tcc_cooling 12288 0
x86_pkg_temp_thermal 16384 0
snd_compress 28672 2 snd_soc_avs,snd_soc_core
intel_powerclamp 24576 0
ac97_bus 12288 1 snd_soc_core
snd_pcm_dmaengine 16384 1 snd_soc_core
coretemp 24576 0
snd_hda_intel 69632 0
iwlmvm 860160 0
snd_intel_dspcfg 45056 5 snd_soc_avs,snd_hda_intel,snd_sof,snd_sof_intel_ hda_common,snd_soc_skl
snd_intel_sdw_acpi 16384 2 snd_sof_intel_hda_common,snd_intel_dspcfg
kvm_intel 446464 0
ee1004 16384 0
mei_hdcp 28672 0
mei_wdt 16384 0
mac80211 1744896 1 iwlmvm
mei_pxp 20480 0
snd_hda_codec 225280 7 snd_soc_avs,snd_hda_codec_hdmi,snd_soc_hda_codec ,snd_hda_intel,snd_soc_hdac_hda,snd_soc_skl,snd_sof_intel_hda
kvm 1445888 1 kvm_intel
libarc4 12288 1 mac80211
snd_hda_core 151552 10 snd_soc_avs,snd_hda_codec_hdmi,snd_soc_hda_code c,snd_hda_intel,snd_hda_ext_core,snd_hda_codec,snd_sof_intel_hda_common,snd_soc_ hdac_hda,snd_soc_skl,snd_sof_intel_hda
snd_hwdep 20480 1 snd_hda_codec
rapl 20480 0
btusb 86016 0
iwlwifi 540672 1 iwlmvm
snd_pcm 196608 13 snd_soc_avs,snd_hda_codec_hdmi,snd_hda_intel,sn d_hda_codec,soundwire_intel,snd_sof,snd_sof_intel_hda_common,snd_compress,snd_so c_core,snd_sof_utils,snd_soc_skl,snd_hda_core,snd_pcm_dmaengine
intel_cstate 24576 0
btrtl 36864 1 btusb
btintel 65536 1 btusb
wmi_bmof 12288 0
btbcm 24576 1 btusb
snd_timer 53248 1 snd_pcm
e1000e 385024 0
btmtk 12288 1 btusb
snd 159744 9 snd_hda_codec_hdmi,snd_hwdep,snd_hda_intel,snd_h da_codec,snd_sof,snd_timer,snd_compress,snd_soc_core,snd_pcm
intel_wmi_thunderbolt 16384 0
intel_uncore 274432 0
cfg80211 1421312 3 iwlmvm,iwlwifi,mac80211
bluetooth 1056768 27 btrtl,btmtk,btintel,btbcm,bnep,btusb
pcspkr 12288 0
i2c_i801 36864 0
soundcore 16384 1 snd
i2c_smbus 20480 1 i2c_i801
mei_me 57344 3
rfkill 40960 7 iwlmvm,bluetooth,cfg80211
idma64 20480 0
mei 204800 7 mei_wdt,mei_hdcp,mei_pxp,mei_me
intel_pch_thermal 20480 0
intel_xhci_usb_role_switch 12288 0
vfat 24576 1
intel_pmc_core 126976 0
intel_vsec 20480 1 intel_pmc_core
pmt_telemetry 16384 1 intel_pmc_core
fat 114688 1 vfat
pmt_class 16384 1 pmt_telemetry
joydev 32768 0
acpi_pad 184320 0
loop 45056 0
dm_multipath 53248 0
nfnetlink 20480 4 nf_tables,ip_set
zram 40960 2
xfs 3194880 6
i915 4657152 1
hid_logitech_hidpp 81920 0
crct10dif_pclmul 12288 1
crc32_pclmul 12288 0
crc32c_intel 16384 0
polyval_clmulni 12288 0
polyval_generic 12288 1 polyval_clmulni
i2c_algo_bit 20480 1 i915
nvme 69632 8
drm_buddy 20480 1 i915
ghash_clmulni_intel 16384 0
ttm 114688 1 i915
nvme_core 245760 9 nvme
sha512_ssse3 53248 0
drm_display_helper 274432 1 i915
sha256_ssse3 36864 0
sha1_ssse3 32768 0
nvme_auth 28672 1 nvme_core
wdat_wdt 20480 0
cec 98304 2 drm_display_helper,i915
video 77824 1 i915
wmi 36864 3 video,intel_wmi_thunderbolt,wmi_bmof
pinctrl_sunrisepoint 28672 0
hid_logitech_dj 45056 0
scsi_dh_rdac 16384 0
scsi_dh_emc 12288 0
scsi_dh_alua 28672 0
ip6_tables 28672 0
ip_tables 28672 0
fuse 229376 1

It tells you the size of the module. It also tells you all of the other modules that depend on that particular module.
 
modinfo can return quite a bit of information.

modinfo bluetooth
Code:
filename:       /lib/modules/6.9.6-200.fc40.x86_64/kernel/net/bluetooth/bluetooth.ko.xz
alias:          net-pf-31
license:        GPL
version:        2.22
description:    Bluetooth Core ver 2.22
author:         Marcel Holtmann <[email protected]>
srcversion:     BE02024B20B0466FC918B9E
depends:        rfkill
retpoline:      Y
intree:         Y
name:           bluetooth
vermagic:       6.9.6-200.fc40.x86_64 SMP preempt mod_unload
sig_id:         PKCS#7
signer:         Fedora kernel signing key
sig_key:        1D:62:5D:9C:69:69:19:60:C0:DE:80:48:D4:23:86:46:5A:E5:8F:68
sig_hashalgo:   sha256
signature:      42:58:6E:F0:AD:4C:94:22:64:85:A7:0D:9E:09:55:A5:F7:46:01:02:
                49:AB:FC:DE:42:8A:A5:FD:C8:FF:92:57:35:85:5F:BD:F6:FB:42:C4:
                E8:64:8F:8A:A4:26:C4:0E:D5:8B:01:9B:CC:39:34:9A:2D:05:30:0F:
                94:47:EA:57:7A:E6:E3:AC:43:D4:9E:8D:38:66:60:36:EF:DD:99:0F:
                0E:B0:60:B8:45:09:E6:FB:14:F1:2A:62:DB:73:F8:16:D7:EE:BE:AB:
                FF:FD:A6:9C:C4:99:01:70:CA:3F:BA:1A:18:9F:7B:66:8F:4B:5C:71:
                E5:1C:BB:E7:84:C3:79:CF:39:F1:AE:6A:DE:8F:84:C2:0E:7C:AE:F5:
                3F:B0:C3:1B:68:F9:2A:C3:07:A4:C3:21:02:40:C6:2C:67:46:42:A5:
                82:59:3A:5A:EA:C9:C2:E8:19:B4:02:65:5D:08:8C:45:EE:B0:FC:F5:
                76:C0:3F:EE:C7:0C:5D:A3:2C:27:44:B2:06:78:A4:B3:5E:4E:0F:92:
                AD:1E:E2:CE:40:7F:8E:B9:56:C0:31:73:0B:5F:AC:23:43:83:99:10:
                16:32:FF:1E:CE:B0:FC:7A:49:FE:71:9A:4C:D5:D8:D5:6A:90:07:4E:
                1A:CA:E9:7B:7A:EA:86:8D:F3:DF:72:57:FA:F0:7B:95:3A:47:9D:EA:
                B1:7B:FB:B8:01:EB:13:91:1C:FC:15:C9:7C:37:F2:84:89:D6:8B:A1:
                1E:05:30:4F:13:3A:DA:1C:83:19:6B:0E:86:4A:D0:92:E5:69:74:CC:
                69:17:2F:52:B2:EE:8C:0F:C0:98:B1:01:D1:37:18:89:6A:94:2F:26:
                29:37:2E:D2:63:E7:61:94:77:54:BD:CD:AF:86:AD:AF:89:E4:53:2F:
                AE:4A:C1:1F:8E:E1:D2:8F:D0:F0:4F:67:43:75:B4:F1:3C:BE:CF:67:
                D5:76:14:F3:E4:60:28:BF:A9:DF:07:2B:E4:93:17:90:3D:B8:4A:42:
                04:5F:18:AD:A8:0C:6B:BB:1C:00:EA:CC:A6:FE:D9:9E:F8:45:4F:2B:
                06:A4:B6:F6:87:A5:10:45:71:E4:2F:59:B6:D1:A0:3D:75:43:33:8B:
                99:4E:91:98:ED:F1:6A:9E:42:13:A4:80:D7:FC:69:D4:F1:5B:28:4D:
                31:04:94:F6:B0:02:31:31:87:4C:8E:B6:7F:F9:8A:A6:A4:BB:32:86:
                96:F4:4B:62:71:AB:DC:70:55:51:60:ED:23:C9:DE:64:7F:B6:71:16:
                1F:4B:37:27:D7:22:66:52:3E:04:8F:C6:90:00:5E:9E:12:42:49:31:
                D3:88:2C:59:79:09:F7:BC:A6:07:9C:3D
parm:           disable_esco:Disable eSCO connection creation (bool)
parm:           disable_ertm:Disable enhanced retransmission mode (bool)
parm:           enable_ecred:Enable enhanced credit flow control mode (bool)

This will tell you the version, it will also tell you the minimum kernel version this module is compatible with.
If you are using a Linux distro that uses secure key signing, it will show you the signing key as well.
Usually it will show the developer. Finally.. ( something that is becoming more and more controversial these days )
it will show the license type.
 
Last edited:
When you run the lsmod command, you will often see another number after the size of the module.

nfnetlink 20480 4 nf_tables,ip_set
zram 40960 2
xfs 3194880 6
i915 4657152 1
hid_logitech_hidpp 81920 0
crct10dif_pclmul 12288 1

Notice xfs has a "6" after the size, and nfnetlink has a "4" after the size.
These are the number of instances that are currently loaded.
Notice that hid_logitech_hidpp has a 0, that means the module exists on my system, but it doesn't
currently have a running instance of that module.
xfs has a 6, because I have six different xfs mount points on that particular computer.
So the module has to be loaded 6 times. You don't have to worry about this, the kernel automatically
knows how many instances are needed for something to work.

so if my xfs module is 3,194,880 in size, and I have 6 of these loaded, I'm really using
19,169,280 of space for this module.
 
Last edited:


Members online


Latest posts

Top