7

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 ?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
mathematician1975
  • 1,453
  • 2
  • 24
  • 43
  • You could run `lsmod` to see if there are any modules loaded, or check whether `/lib/modules/\`uname -r\`` exists or check `/proc/modules`... – hhaamu Jul 16 '12 at 09:11
  • @hhaamu Thanks for the suggestion - I was adding a little extra to the question as you added this. There is no /lib/modules on my system. – mathematician1975 Jul 16 '12 at 09:13
  • In this case it seems unlikely that your system has been compiles with modules support. – Marco Jul 16 '12 at 09:15
  • Given your questions, it looks like you should install a less closed distribution on your device. – Gilles 'SO- stop being evil' Jul 17 '12 at 21:44
  • I think I may have to abandon Linux altogether as the OS on my device and use DOS – mathematician1975 Jul 18 '12 at 07:06
  • If your vendor provided you with a Linux kernel, you should also be able to get the sources necessary for you to build it yourself (after enabling modules). If your vendor doesn't provide that, they're in violation of the GPL. – cjm Jul 19 '12 at 09:07

2 Answers2

12

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?

Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
4

Most distributions store a text file with the kernel configuration somewhere. On a Debian system you'll find it in /boot/config-<kernel_version>.

Then you can simply run grep on that file:

grep CONFIG_MODULES /boot/config-<kernel_version>
Marco
  • 33,188
  • 10
  • 112
  • 146