Can I detect if my custom made kernel was built with module support?

6,816

Solution 1

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?

Solution 2

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>
Share:
6,816

Related videos on Youtube

Lewis Wilcock
Author by

Lewis Wilcock

Updated on September 18, 2022

Comments

  • Lewis Wilcock
    Lewis Wilcock over 1 year

    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 ?

    • hhaamu
      hhaamu almost 12 years
      You could run lsmod to see if there are any modules loaded, or check whether /lib/modules/`uname -r` exists or check /proc/modules...
    • Lewis Wilcock
      Lewis Wilcock almost 12 years
      @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.
    • Marco
      Marco almost 12 years
      In this case it seems unlikely that your system has been compiles with modules support.
    • Gilles 'SO- stop being evil'
      Gilles 'SO- stop being evil' almost 12 years
      Given your questions, it looks like you should install a less closed distribution on your device.
    • Lewis Wilcock
      Lewis Wilcock almost 12 years
      I think I may have to abandon Linux altogether as the OS on my device and use DOS
    • cjm
      cjm almost 12 years
      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.
  • Lewis Wilcock
    Lewis Wilcock almost 12 years
    Thanks for your answer. Unfortunately there is no /boot/config-*** on my installation.
  • hhaamu
    hhaamu almost 12 years
    There's also /proc/config.gz if the kernel was configured with CONFIG_PROC_CONFIG
  • Lewis Wilcock
    Lewis Wilcock almost 12 years
    @hhaamu I don't seem to have that either.
  • Lewis Wilcock
    Lewis Wilcock almost 12 years
    Thanks for this. It sounds like I will have to abandon this then.