Page List

Wednesday, June 12, 2024

CBT Nugget: Linux Server Administration - 7. Loading Kernel Modules on Boot

Loading Kernel Modules on Boot

Kernel modules are dynamically loadable pieces of code that extend the functionality of the kernel. They can provide drivers for hardware, support for filesystems, and other kernel features. Loading these modules at boot time ensures that the necessary functionalities are available when the system starts.

Methods for Loading Kernel Modules on Boot

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

    • This file lists the modules to be loaded at boot. Each module should be listed on a separate line.

    Example /etc/modules:

    plaintext
    # /etc/modules: kernel modules to load at boot time. # This file contains the names of kernel modules that should be loaded # at boot time, one per line. Lines beginning with "#" are ignored. fuse vboxdrv
  2. Using /etc/modprobe.d/ Configuration Files:

    • Configuration files in this directory can be used to specify options for modules and to ensure they are loaded at boot. These files typically have a .conf extension.

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

    plaintext
    # Load the dummy module at boot install dummy /sbin/modprobe --ignore-install dummy # Set options for the dummy module options dummy numdummies=2
  3. Using /etc/rc.local:

    • This script runs at the end of each multiuser runlevel. You can add modprobe commands to load modules.

    Example /etc/rc.local:

    sh
    #!/bin/sh -e # # rc.local # # This script is executed at the end of each multiuser runlevel. # Make sure that the script will "exit 0" on success or any other # value on error. # # By default this script does nothing. /sbin/modprobe dummy exit 0
  4. Using Systemd (for Systems with Systemd):

    • Systemd can be used to load kernel modules using unit files.

    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

    Enabling the Service:

    sh
    sudo systemctl enable load-modules.service sudo systemctl start load-modules.service
  5. Using /etc/init.d/ Scripts (SysVinit):

    • On systems using SysVinit, custom scripts can be created in /etc/init.d/ to load modules.

    Example /etc/init.d/load-modules:

    sh
    #!/bin/sh ### BEGIN INIT INFO # Provides: load-modules # Required-Start: $all # Required-Stop: # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Load custom kernel modules ### END INIT INFO case "$1" in start) echo "Loading custom kernel modules" modprobe dummy modprobe vboxdrv ;; stop) echo "Unloading custom kernel modules" modprobe -r dummy modprobe -r vboxdrv ;; *) echo "Usage: $0 {start|stop}" exit 1 esac exit 0

    Making the Script Executable and Enabling It:

    sh
    sudo chmod +x /etc/init.d/load-modules sudo update-rc.d load-modules defaults

Summary

Loading kernel modules at boot can be managed in various ways depending on the Linux distribution and init system in use. Common methods include listing modules in /etc/modules, creating configuration files in /etc/modprobe.d/, adding modprobe commands to /etc/rc.local, using systemd unit files, and creating init scripts in /etc/init.d/. These methods ensure that necessary kernel functionalities are available when the system starts, providing essential support for hardware and other kernel features.

פוסט מוצג

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...