Detect If Custom Kernel Was Built with Module Support

kernelkernel-moduleslinux

I have been provided with a vendor supplied minimal linux installation. From an answer to a previous question I discovered that it is possible to build a kernel with or without module support. I have a CANBUS device that I need to attach which comes with drivers in the form of .ko files. I would like to be able to install these with the provided install scripts, but firstly I need to know if my kernel was built with module support – is it possible for me to detect this from the command line??

When I run lsmod it returns nothing so I know that there are no .ko files there at the moment – but doest this mean that the kernel won't allow me to install a .ko file ?

Best Answer

If you have a /proc filesystem, the file /proc/modules exists if and only if the kernel if compiled with module support. If the file exists but is empty, your kernel supports modules but none are loaded at the moment. If the file doesn't exist, your kernel cannot load any module.

It's technically possible to have loadable module support without /proc. You can check for the presence of the init_module and delete_module system calls in the kernel binary. This may not be easy if you only have a compressed binary (e.g. vmlinuz or uImage). See How do I uncompress vmlinuz to vmlinux? for vmlinuz. Once you've managed to decompress the bulk of the kernel, search for the string sys_init_module.

Note that if modules are supported, you'll need additional files to compile your own modules anyway: kernel headers. These are C header files (*.h), some of which are generated when the kernel is compiled (so you can't just take them from the kernel source). See What does a kernel source tree contain? Is this related to Linux kernel headers?

Related Question