Locating Linux kernel headers and sources for module builds On a traditional system preparing to build a modularized kernel, where are the kernel headers and source commonly located?

Difficulty: Easy

Correct Answer: /usr/src/linux

Explanation:


Introduction / Context:
Compiling a kernel or out-of-tree kernel modules requires matching headers and often the full source tree. Historically, distributions placed the kernel source and headers in a conventional directory to simplify builds and documentation references.



Given Data / Assumptions:

  • The system uses a traditional layout (not containerized or using distribution-specific variants).
  • Packages kernel-headers and kernel-source (or kernel-devel) are installed.
  • We are preparing to build a modularized kernel or modules.


Concept / Approach:

Older and many instructional references point to /usr/src/linux as the canonical path for the Linux source tree or a symlink to the active kernel source. While modern distributions may use versioned directories (for example, /usr/src/kernels/), the commonly taught location remains /usr/src/linux in fundamentals courses and legacy documentation.



Step-by-Step Solution:

Install kernel headers and source (or kernel-devel) via the package manager.Verify presence or symlink: ls -l /usr/src and check for linux.Point build systems (for example, make) to that tree as needed.Ensure the source matches the running kernel version to avoid ABI mismatches.


Verification / Alternative check:

Run uname -r to get the running kernel version and ensure your headers under /usr/src/linux or /usr/src/kernels match. If not, install the appropriate kernel-devel package.



Why Other Options Are Wrong:

  • /usr/local: general local installs; not the standard kernel source path.
  • /usr/sre/redhat: misspelled/nonstandard path.
  • /usr/bin: executable binaries, not source trees.
  • None of the above: incorrect because /usr/src/linux is the conventional answer.


Common Pitfalls:

Building against mismatched headers, removing the linux symlink, or assuming the headers are installed by default. Always align versions for reliable builds.


Final Answer:

/usr/src/linux

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion