Garden of KnowledgeApplied Sciences › Computer Science › Software › Security › Certifications › LFCS

q43-kernel-modules

Énoncé§

Solve this question on: terminal

  1. List all currently loaded kernel modules and write the count into /opt/course/43/count.
  2. Show detailed information about the vfat module and write its description line into /opt/course/43/vfat-desc.
  3. Load the dummy module now, then unload it.
  4. Ensure the dummy module is loaded automatically at boot.
  5. Blacklist the pcspkr module so it is never loaded automatically.

Solution§

Kernel modules are pieces of code (drivers, filesystems, network protocols) that can be loaded into and removed from the running kernel on demand. Modules live under /lib/modules/$(uname -r)/ and have the .ko extension.

Step 1 — List loaded modules§

lsmod                               # name, size, used-by count, dependents
lsmod | wc -l                       # includes the header line
# count without the header:
echo $(($(lsmod | wc -l) - 1)) > /opt/course/43/count

lsmod is just a formatted view of /proc/modules.

Step 2 — Inspect a module§

modinfo vfat                        # full metadata
modinfo -F description vfat         # only the description field
modinfo -n vfat                     # path to the .ko file
modinfo -F depends vfat             # dependencies

modinfo -F description vfat > /opt/course/43/vfat-desc

modinfo works on a module name or a .ko path, even if the module is not loaded.

Step 3 — Load and unload now§

sudo modprobe dummy                 # load (resolves dependencies)
lsmod | grep dummy                  # verify
sudo modprobe -r dummy              # unload (and unused deps)

Pass parameters when loading:

sudo modprobe dummy numdummies=2
modinfo -p dummy                    # list accepted parameters

Step 4 — Load automatically at boot§

Create a file under /etc/modules-load.d/ (one module name per line):

echo dummy | sudo tee /etc/modules-load.d/dummy.conf

systemd-modules-load.service reads every *.conf in /etc/modules-load.d/ at boot and modprobes each listed module.

To also pass parameters at every load, add a file under /etc/modprobe.d/:

echo "options dummy numdummies=2" | sudo tee /etc/modprobe.d/dummy.conf

Debian also reads the legacy /etc/modules file for boot-time loading; /etc/modules-load.d/ is the systemd-native, distro-agnostic way.

Step 5 — Blacklist a module§

echo "blacklist pcspkr" | sudo tee /etc/modprobe.d/blacklist-pcspkr.conf

blacklist prevents automatic loading (by udev/hardware detection or as a dependency-by-alias). It does not stop a manual modprobe pcspkr. To block even manual loading, redirect the install command:

echo "install pcspkr /bin/false" | sudo tee -a /etc/modprobe.d/blacklist-pcspkr.conf

A module already loaded into the running kernel must be removed manually (modprobe -r pcspkr) or after a reboot. If it is built into the initramfs, regenerate it:

sudo update-initramfs -u              # Debian/Ubuntu
sudo dracut -f                        # RHEL/Fedora

Reference§

CommandPurpose
lsmodlist loaded modules
modinfo NAMEshow module metadata / parameters
modprobe NAMEload (with dependency resolution)
modprobe -r NAMEunload
insmod / rmmodlow-level load/unload (no deps)
depmodrebuild modules.dep after adding a .ko
File / directoryRole
/etc/modules-load.d/*.confmodules to load at boot
/etc/modprobe.d/*.confoptions, aliases, blacklist, install rules
/lib/modules/$(uname -r)/the modules themselves
/proc/modulesraw loaded-module table (source of lsmod)
—The Gardener