I'm creating a program that interacts withkernel headers. The user can provide a path to the location of the headers, but first I would like to be able discover existing kernel headers on the users's machine based on convention. This apparently varies between distributions and tools. I know technically linux is fully customizable but I'm trying to understand what conventions apply to the mainstream distros:

  1. who creates /lib/modules/$version and when?
  2. are there guidelines for the structure of /lib/modules besides the /kernel and /extra subdirectories?
  3. are /build and /source expected to always exist under /lib/modules? (both of them?)
  4. is it acceptable that /build and /source are sometimes symlinks and sometimes not?
  5. does the headers and source come together? I've noticed that most distros offer a kernel headers or kernel development package. how is this related?

1 Answer 1

  1. Normally make modules_install but of course distros just package all these modules.
  2. This looks like a Debian/Ubuntu thing. depmod just traverses all the subdirectories under /lib/modules/$version
  3. For Fedora/RHEL/CentOS or the Linux kernel installed from source - the answer is yes.
  4. Normally they are always symlinks
  5. Almost never. There are kernel development headers which are required to build modules, and most distros don't even offer the option of installing the kernel source - it doesn't make a lot of sense for the end user.

Instead of reinventing the wheel, I'd recommend that you take a look at kernel modules build systems offered by VirtualBox, NVIDIA or VMWare. They are well tested and support dozens of distros.

  • thanks. is the build/source links defined by make modules_install? or by the kernel headers packages?
    – itaysk
    Commented Dec 6, 2020 at 19:22
  • 1
    make modules_install creates these symlinks but distros may override them. Commented Dec 6, 2020 at 20:15
  • 1
    re 2, I don't think it's a Debian thing because it's mentioned in kbuild documentation github.com/torvalds/linux/blob/v5.8/Documentation/kbuild/…
    – itaysk
    Commented Dec 7, 2020 at 8:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .