Ubuntu – How to get a list of installed external kernel modules

kernelkernel-moduleslinuxrhelUbuntu

From the documentation of Linux kernel 3.2 (Documentation/kbuild/modules.txt)

=== 5. Module Installation

Modules which are included in the kernel are installed in the
directory:

    /lib/modules/$(KERNELRELEASE)/kernel/

And external modules are installed in:

    /lib/modules/$(KERNELRELEASE)/extra/

This implies that if I look into /lib/modules/$(KERNELRELEASE)/extra/ I can find all installed external kernel modules. However, I find that the official Nvidia display driver installs nvidia.ko into /lib/modules/$(KERNELRELEASE)/kernel/drivers/video/. This contradicts the above rule and suggests that the path is not a reliable indicator of included/external modules.

How to get a list of external kernel modules installed? If the distro matters, I'd like to know the answer for RHEL 6 and Ubuntu 10.04.

Best Answer

For Debian/Ubuntu, something like

dpkg -S *.ko | grep /lib/modules | grep -v linux-image

should work. Disclaimer: I'm illiterate when it comes to pattern matching, so there are probably better ways of doing this. On my system, I get

nvidia-kernel-2.6.32-5-vserver-686-bigmem: /lib/modules/2.6.32-5-vserver-686-bigmem/nvidia/nvidia.ko
nvidia-kernel-2.6.26-2-vserver-686-bigmem: /lib/modules/2.6.26-2-vserver-686-bigmem/nvidia/nvidia.ko
nvidia-kernel-2.6.26-1-vserver-686-bigmem: /lib/modules/2.6.26-1-vserver-686-bigmem/nvidia/nvidia.ko

This does assume that all installed modules are known to the packaging system, but this is generally a good idea anyway. At least on Debian, installing kernel modules as binary packages is generally possible. This approach has the advantage that it tells you which package a kernel module belongs to. Similar approaches should work with other Linux distributions which use a package management system; i.e. most of them.

Since the location of third party modules is similar to those of the in-kernel modules, it is not easy to distinguish them. Querying the package manager makes things easier. However, in my currently running kernel, in the directory /lib/modules/2.6.32-5-vserver-686-bigmem, I notice that the nvidia modules are in a separate directory from the main kernel modules, namely /lib/modules/2.6.32-5-vserver-686-bigmem/nvidia vs /lib/modules/2.6.32-5-vserver-686-bigmem/kernel. I don't know if such a layout is Debian policy or not. The closest thing to Debian kernel policy I am aware of is The Debian Kernel Handbook, but I did not find anything relevant there. Of course, Ubuntu is not bound by Debian policy in any case.

Related Question