How to Check Linux Kernel Module (*.ko) Version Without Loading It


3 views

When working with Linux kernel modules (*.ko files), version checking is crucial for compatibility verification and debugging. While modprobe -v works for loaded modules, we often need to inspect version metadata without module loading.

The most straightforward approach is using modinfo, which extracts module information directly from the .ko file:

modinfo /path/to/module.ko | grep -E '^version|^vermagic'

Example output for a network driver:

version:        1.2.5
vermagic:       5.15.0-76-generic SMP mod_unload modversions 

For more technical inspection, you can examine the ELF sections directly:

readelf -p .modinfo /path/to/module.ko | grep version

Another low-level approach using objdump:

objdump -s -j .modinfo /path/to/module.ko | grep version

Remember these important details:

  • Modules might have both 'version' (module version) and 'vermagic' (kernel compatibility)
  • Some modules might not expose version information
  • Always check module dependencies with modinfo --field depends

Here's a bash function to simplify version checking:

function ko_version() {
    local ko_path=$1
    echo "Module: $(basename $ko_path)"
    modinfo "$ko_path" | awk '/^version:|^vermagic:/ {print}'
}

# Usage:
ko_version /lib/modules/$(uname -r)/kernel/drivers/net/ethernet/intel/e1000.ko

If you encounter issues:

# Ensure tools are installed
sudo apt install kmod binutils  # Debian/Ubuntu
sudo yum install kmod binutils  # RHEL/CentOS

# Check file permissions
ls -l /path/to/module.ko

# Verify file integrity
file /path/to/module.ko | grep 'ELF.*LSB'

Linux kernel modules (.ko files) contain version information that's crucial for compatibility checks and debugging. While modprobe -v works for loaded modules, we often need to inspect module versions without loading them.

The most reliable way is using the modinfo command:

modinfo /path/to/module.ko | grep -E 'vermagic|version'

Example output for a WiFi driver:

version:        1.1.4.2.5
vermagic:       5.15.0-76-generic SMP mod_unload modversions 

For modules where modinfo doesn't work, you can read the ELF sections directly:

readelf -p .modinfo /path/to/module.ko | grep version

Sometimes you need to verify the build signature against your running kernel:

uname -r
modinfo /path/to/module.ko | grep vermagic

Let's check an Nvidia driver module version before installation:

# First locate the module
find /lib/modules/ -name "nvidia.ko"

# Then check its version
modinfo /lib/modules/$(uname -r)/kernel/drivers/video/nvidia.ko | grep version

For signed modules (common in secure boot environments), you might need additional flags:

modinfo --signature /path/to/module.ko

Remember that some modules might have version information in different sections. If the above methods don't work, try:

strings /path/to/module.ko | grep -i version