Page List

Wednesday, June 12, 2024

CBT Nugget: Linux Server Administration - 8. Manipulating Kernel Modules

Manipulating Kernel Modules

Kernel modules are pieces of code that can be loaded and unloaded into the kernel at runtime. They extend the kernel's capabilities without the need to reboot the system. Understanding how to manipulate kernel modules is crucial for managing system functionality and troubleshooting issues.

Key Commands for Manipulating Kernel Modules

  1. Loading Modules:

    • modprobe: Loads a module and its dependencies.
    • insmod: Loads a module without resolving dependencies.

    Examples:

    sh
    sudo modprobe module_name sudo insmod /path/to/module.ko
  2. Unloading Modules:

    • modprobe -r: Removes a module and its dependencies.
    • rmmod: Removes a module without resolving dependencies.

    Examples:

    sh
    sudo modprobe -r module_name sudo rmmod module_name
  3. Listing Modules:

    • lsmod: Lists all currently loaded modules.

    Example:

    sh
    lsmod
  4. Module Information:

    • modinfo: Displays information about a module, such as its dependencies, parameters, and description.

    Example:

    sh
    modinfo module_name
  5. Viewing Kernel Logs:

    • dmesg: Displays kernel and module-related messages, useful for debugging module loading issues.

    Example:

    sh
    dmesg | grep module_name

Loading Kernel Modules at Boot

To ensure kernel modules are loaded at boot, various methods can be employed depending on the Linux distribution and init system. Here are some common methods:

  1. Using /etc/modules (Debian-based Systems):

    • Add the module names to this file, one per line.

    Example /etc/modules:

    plaintext
    # /etc/modules: kernel modules to load at boot time. fuse vboxdrv
  2. Using /etc/modprobe.d/ Configuration Files:

    • Create a .conf file in this directory to specify modules to load and their options.

    Example /etc/modprobe.d/custom.conf:

    plaintext
    install dummy /sbin/modprobe --ignore-install dummy options dummy numdummies=2
  3. Using Systemd:

    • Create a custom systemd service to load modules at boot.

    Example /etc/systemd/system/load-modules.service:

    ini
    [Unit] Description=Load Custom Kernel Modules After=network.target [Service] Type=oneshot ExecStart=/sbin/modprobe dummy ExecStart=/sbin/modprobe vboxdrv RemainAfterExit=true [Install] WantedBy=multi-user.target

    Enable the Service:

    sh
    sudo systemctl enable load-modules.service sudo systemctl start load-modules.service

Managing Module Dependencies and Options

1. Specifying Module Options:

  • Module options can be set in files within /etc/modprobe.d/.

Example /etc/modprobe.d/custom_options.conf:

plaintext
options module_name option_name=option_value

2. Blacklisting Modules:

  • Prevent certain modules from loading automatically.

Example /etc/modprobe.d/blacklist.conf:

plaintext
blacklist module_name

Example Scenario

Loading and Configuring the dummy Module:

  1. Load the Module:

    sh
    sudo modprobe dummy
  2. Set Module Options: Create a configuration file /etc/modprobe.d/dummy.conf:

    plaintext
    options dummy numdummies=2
  3. Ensure the Module Loads at Boot: Add the module to /etc/modules:

    plaintext
    dummy
  4. Verify the Module is Loaded:

    sh
    lsmod | grep dummy
  5. Check Kernel Messages:

    sh
    dmesg | grep dummy

Summary

Manipulating kernel modules involves loading, unloading, listing, and configuring modules to extend kernel functionality dynamically. Key commands include modprobe, insmod, rmmod, and lsmod. Modules can be configured to load at boot using /etc/modules, /etc/modprobe.d/, systemd services, and other methods. Proper management of module dependencies and options ensures a stable and functional system.

פוסט מוצג

CBT Nugget: Linux Server Administration - 13.Identifying Red Hat and CentOS Network Configuration Files

13.Identifying Red Hat and CentOS Network Configuration Files In Red Hat Enterprise Linux (RHEL) and CentOS, network configuration is manag...