TécnicoSistemas

Hub de Contenidos:

  • Técnico Sistemas
  • Sistema
  • Development
    • Testing Environment Setup
      • Setting Up LTP Test Cases on a Linux VM Environment
      • Setting Up a VM to Boot with a Copied Kernel
      • Enabling the Boot Menu During Boot
      • Understanding Bootloader Directories and Customizing GRUB
      • Determine Boot Mode and Bootloader
      • Querying XML File Configuration with libvirt Shell
      • Inspecting the MBR to Identify the Bootloader
      • Determining the Bootloader and Kernel/Ramdisk Loading in a KVM VM
      • Focusing on the VM Context: How the Kernel and Initramfs Are Loaded
      • Understanding grub2-editenv list Output: Saved Entry Hash
      • Working with Older Kernel Versions on CentOS 7: Challenges and Solutions
      • Using Autotools in the LTP Build Process
      • LTP build log
      • Building the Documentation
      • Check Headers
      • Debuggin Kernel Headers
      • LTP Configuration Debugging Analysis
      • How to Fix Missing linux/module.h in LTP Configuration
      • Understanding /usr/src/linux Symlink Importance
        • The Missing /usr/src/linux Directory
        • Creating the Symlink (Solution)
      • The /usr/src/linux Reality Check
      • Debugging Missing Kernel Headers in LTP Build System
      • List of Symbols
      • Using text Macros to Check for Headers
      • Understanding Directory Permission Strings
      • Check GCC Search Path for Kernel Headers in GNU/Linux
      • Overview of Autotools Primary Concepts
      • Confirming Bootloader and Kernel Loading with UUID
    • Driver Development
    • Hardware and System Resources
    • System Configuration
    • Unordered Topics
    • Documentación del Kernel
  • Siglas
  • Release Notes & Changelog
TecnicoSistemas
  • Development
  • Testing Environment Setup
  • Understanding /usr/src/linux Symlink Importance
  • View page source

Understanding /usr/src/linux Symlink Importance

The Missing /usr/src/linux Directory

1. Why the Path Doesn’t Exist

  • Modern Linux distributions (especially RHEL/CentOS) no longer create /usr/src/linux by default

  • Kernel headers are installed to version-specific paths like:

    /usr/src/kernels/$(uname -r)/
    

2. Why This Breaks Module Building

  • Many build systems (including LTP and kernel module builds) historically expected:

    /usr/src/linux/include/linux/module.h
    
  • Without this symlink:

    • Compiler cannot find kernel headers

    • Module builds fail with “linux/module.h not found”

    • LTP kernel tests cannot be compiled

3. Why It’s Critical for LTP

  • LTP’s kernel tests require:

    • Exact kernel headers matching running kernel

    • Standard header paths expected by build system

  • Without proper headers:

    • All kernel-space tests will fail

    • Key functionality (syscalls, drivers, filesystems) won’t be tested

    • configure may disable critical test cases

4. Historical Context

  • Traditional Linux builds used /usr/src/linux symlink

  • Modern distributions use versioned paths for:

    • Parallel kernel support

    • Cleaner package management

    • Multiple kernel versions coexistence

5. Impact on Module Building

  • Kernel modules must be built against exact headers:

    • Version mismatch causes:

      • Module loading failures

      • Kernel panics

      • Undefined symbol errors

  • /usr/src/linux symlink ensures:

    • Consistent build paths

    • Version correctness

    • Build system compatibility

Creating the Symlink (Solution)

1. Verify Kernel Headers Exist

ls /usr/src/kernels/$(uname -r)/include/linux/module.h

2. Create Symlink

sudo ln -s /usr/src/kernels/$(uname -r) /usr/src/linux

3. Verify

ls -l /usr/src/linux/include/linux/module.h
# Should show valid symlink chain

4. Permanent Fix

For persistent solution across kernel updates:

echo "ln -sf /usr/src/kernels/\$(uname -r) /usr/src/linux" | sudo tee /etc/kernel/postinst.d/linux-symlink
sudo chmod +x /etc/kernel/postinst.d/linux-symlink
Previous Next

© Copyright 2024, Raul Vilchez.

Built with Sphinx using a theme provided by Read the Docs.