View, load, or unload a kernel module

Author: name contact BSD flavour

Reviewer: name contact BSD flavour

Reviewer: name contact BSD flavour


Concept

Undertand the difference between a statically compiled kernel and one that uses loadable kernel modules. Be able to view, load and unload kernel modules on each BSD system but should be aware that kernel modules are discouraged on NetBSD and OpenBSD systems.

TODO: Are they really discouraged? Where documented?

Introduction

Kernel modules provide extra functionality that a system administrator can add to their running kernel. Common examples include audio device drivers, network interfaces, RAID and other hardware drivers, extra filesystems support, packet filtering, binary compatibility support for other operating systems (like Linux), and console screen savers. In most cases, this extra functionality or hardware support can be configured and then built in to your monolithic kernel. But using kernel modules may be more convenient.

On FreeBSD and DragonFly, the kernel module filenames have an .ko extension. NetBSD and OpenBSD kernel modules end with .o.

On FreeBSD and DraogonFlyBSD, the default kernel modules are located at /boot/kernel. On NetBSD and OpenBSD kernel modules are at /usr/lkm. The generic system in OpenBSD contains no loadable kernel modules.

TODO: list a few common modules TODO: show how to find modules

FreeBSD and DragonFly use kldload, kldunload, and kldstat to load, unload and to view details, respectively. NetBSD and OpenBSD use the modload, modunload, and modstat tools.

Examples

The following is an example of runninng kldstat to list modules on a DragonFly system:

""# kldstat ""Id Refs Address Size Name "" 1 5 0xc0100000 5eff14 kernel "" 2 1 0xc06f0000 2b58 ecc.ko "" 3 1 0xc06f3000 591d0 acpi.ko "" 4 1 0xdd68c000 3000 null.ko

The "refs" column shows the number of modules referenced by the kernel object. TODO: The "address" column shows the load address of (the pointer to) the kernel object. The "size" is the size in hexadecimal.

In the above examples, "ecc" is for AMD64 ECC memory controller, "acpi" is for ACPI power management, and "null" provides the mount_null filesystem support.

TODO: explain why the kernel listed

TODO: should this mention -v? maybe not for BSDA?

Practice Exercises

More information

kldstat(8), kldload(8), kldunload(8), and loader.conf(5); modstat(8), modload(8), modunload(8), and lkm.conf(5)