uname and lsmod - finding out about your kernel.

dos2unix

Well-Known Member
Joined
May 3, 2019
Messages
3,490
Reaction score
3,224
Credits
31,265

Gathering Information About Your Linux Kernel and Modules​

What is a Kernel Module?​

A kernel module is a piece of code that can be loaded into the kernel to extend its functionality. This allows the kernel to support new hardware, filesystems, or other features without needing to be recompiled. Kernel modules can be loaded and unloaded dynamically, making them very flexible.

Internal vs. Dynamic Kernel Modules​

  • Internal Kernel Modules: These are built directly into the kernel. They are always present and cannot be unloaded without rebooting the system.
  • Dynamic Kernel Modules: These can be loaded and unloaded at runtime using commands like modprobe or insmod. They provide greater flexibility as they can be added or removed as needed without rebooting.

Using uname to Gather Kernel Information​

The uname command provides system information, including the kernel version and architecture. Here are some popular flags:

  • -a: Displays all available system information.
  • -r: Shows the kernel release.
  • -m: Displays the machine hardware name.

Examples:​

Code:
uname -a
# Output: Linux hostname 5.15.0-30-generic #31-Ubuntu SMP Thu May 5 10:00:34 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

uname -r
# Output: 5.15.0-30-generic

uname -m
# Output: x86_64

Using lsmod to List Loaded Modules​

The lsmod command lists all currently loaded kernel modules. This can help you identify which modules are being used for sound, network, Wi-Fi, and video.

Example:​

Code:
lsmod
# Output:
# Module                  Size  Used by
# snd_hda_codec_hdmi     49152  1
# snd_hda_intel          36864  3
# iwlwifi               200704  1
# nvidia              12328960  30

Using modinfo to Get Module Information​

The modinfo command provides detailed information about a specific kernel module, such as its description, author, and dependencies.

Examples:​

Code:
modinfo snd_hda_intel
# Output:
# filename:       /lib/modules/5.15.0-30-generic/kernel/sound/pci/hda/snd-hda-intel.ko
# description:    Intel HDA driver
# author:         Takashi Iwai <[email protected]>
# license:        GPL
# srcversion:     1234567890ABCDEF1234567
# depends:        snd-hda-codec,snd-pcm,snd
# retpoline:      Y
# intree:         Y
# name:           snd_hda_intel
# vermagic:       5.15.0-30-generic SMP mod_unload modversions

modinfo iwlwifi
# Output:
# filename:       /lib/modules/5.15.0-30-generic/kernel/drivers/net/wireless/intel/iwlwifi/iwlwifi.ko
# description:    Intel(R) Wireless WiFi driver for Linux
# author:         Intel Corporation <[email protected]>
# license:        GPL
# srcversion:     1234567890ABCDEF1234567
# depends:        cfg80211
# retpoline:      Y
# intree:         Y
# name:           iwlwifi
# vermagic:       5.15.0-30-generic SMP mod_unload modversions

Using insmod to Insert a Module​

The insmod command inserts a module into the Linux kernel. Unlike modprobe, it does not handle dependencies automatically, so you need to ensure all required modules are loaded first.

Example:​

Code:
sudo insmod /lib/modules/$(uname -r)/kernel/drivers/net/ethernet/intel/e1000e/e1000e.ko
# Output: (No output if successful, errors if any issues)

Using modprobe to Insert a Module​

The modprobe command is more advanced than insmod as it automatically handles module dependencies.

Examples:​

  1. Loading a Module:
Code:
sudo modprobe e1000e
# Output: (No output if successful)

  1. Removing a Module:
Code:
sudo modprobe -r e1000e
# Output: (No output if successful)

  1. Pretend to Load a Module (Dry Run):
Code:
sudo modprobe --dry-run e1000e
# Output: insmod /lib/modules/$(uname -r)/kernel/drivers/net/ethernet/intel/e1000e/e1000e.ko

Searching for Modules Using dmesg | grep module​

The dmesg command prints the kernel ring buffer messages, which can be filtered using grep to find specific module-related information.

Example:​

Code:
dmesg | grep e1000e
# Output:
# [    1.234567] e1000e: Intel(R) PRO/1000 Network Driver - 3.2.6-k
# [    1.234567] e1000e: Copyright(c) 1999 - 2015 Intel Corporation.
# [    1.234567] e1000e 0000:00:19.0: Interrupt Throttling Rate (ints/sec) set to dynamic conservative mode

By using these commands, you can effectively manage kernel modules on your Linux system, ensuring that you have the necessary drivers and features loaded as needed. This can be particularly useful for troubleshooting and system administration tasks.


I hope this helps!
 


Members online


Latest posts

Top