KLD(4)

๐Ÿ“ฆ
version 15.1 ยท 2 versions
, in freebsd 15.1, nixpkgs unstable

๐Ÿ’– NAME ๐Ÿ’– โ€” KLD(4) in the Kernel Interfaces Manual

okay so bestie, meet kld: the dynamic kernel linker facility. This is the manual page for KLD(4) from the Kernel Interfaces Manual, and yes, she is a whole main character in the FreeBSD kernel world. ๐Ÿซถโœจ

โœจ DESCRIPTION โœจ

First things first, no cap: the LKM (Loadable Kernel Modules) facility has been deprecated in FreeBSD 3.0 and above in favor of the kld interface. ๐Ÿ’€ Like, LKM is the ex; kld is the glow-up.

This interface, like its predecessor, allows the system administrator to dynamically add and remove functionality from a running system. โœจ That's the whole vibe. This ability also helps software developers to develop new parts of the kernel without constantly rebooting to test their changes. ๐Ÿ˜ญ literally saving them from reboot roulette.

Various types of modules can be loaded into the system. There are several defined module types, listed below, which can be added to the system in a predefined way. In addition, there is a generic type, for which the module itself handles loading and unloading. ๐ŸŽ€ iykyk.

The FreeBSD system makes extensive use of loadable kernel modules, and provides loadable versions of most file systems, the NFS client and server, all the screen-savers, and the Linux emulator. ๐Ÿ‘‘ obsessed. kld modules are placed by default in the /boot/kernel directory along with their matching kernel. ๐Ÿฆ‹

The kld interface is used through the kldload(8), kldunload(8) and kldstat(8) programs. Bestie, here's the trio:

  • kldload(8) โ€” can load either a.out(5) or ELF formatted loadable modules. ๐Ÿงš
  • kldunload(8) โ€” unloads any given loaded module, if no other module is dependent upon the given module. ๐Ÿ’…
  • kldstat(8) โ€” is used to check the status of the modules currently loaded into the system. ๐Ÿ”ฅ
๐Ÿšจ vibe check, bestie: Kernel modules may only be loaded or unloaded if the system security level kern.securelevel is less than one. No cap, that's the rule.

๐ŸŒˆ MODULE TYPES ๐ŸŒˆ

๐ŸŽฎ Device Driver modules ๐ŸŽฎ

New block and character device drivers may be loaded into the system with kld. ๐Ÿซถ Device nodes for the loaded drivers are automatically created when a module is loaded and destroyed when it is unloaded by devfs(4). โœจ Not me loving automation.

You can specify userland programs that will run when new devices become available as a result of loading modules, or existing devices go away when modules are unloaded, by configuring devd(8). ๐ŸŽ€ it's giving helpful configuration energy.

๐ŸŽ€ FILES ๐ŸŽ€

  • /boot/kernel โ€” directory containing module binaries built for the kernel also residing in the directory. ๐Ÿฆ‹
  • /usr/include/sys/module.h โ€” file containing definitions required to compile a kld module. ๐Ÿ’œ
  • /usr/share/examples/kld โ€” example source code implementing a sample kld module. ๐ŸŒธ

๐ŸŒŸ SEE ALSO ๐ŸŒŸ

Go read these too, bestie โ€” they're all linked in the original and we are not skipping a single one: ๐Ÿ’–

๐Ÿฆ‹ HISTORY ๐Ÿฆ‹

History lesson, periodt: the kld facility appeared in FreeBSD 3.0 and was designed as a replacement for the lkm facility, which was similar in functionality to the loadable kernel modules facility provided by SunOS 4.1.3. ๐Ÿ‘‘ iconic lineage.

๐Ÿ’… AUTHORS ๐Ÿ’…

The kld facility was originally implemented by Doug Rabson <dfr@FreeBSD.org>. ๐Ÿซถ show some respect to the OG.

๐Ÿ’€ BUGS ๐Ÿ’€

Okay bestie, real talk โ€” these are the known bugs and gotchas, and they are not cute:

  • If a module B, is dependent on another module A, but is not compiled with module A as a dependency, then kldload(8) fails to load module B, even if module A is already present in the system. ๐Ÿ˜ญ
  • If multiple modules are dependent on module A, and are compiled with module A as a dependency, then kldload(8) loads an instance of module A when any of the modules are loaded. ๐Ÿ™ˆ
  • If a custom entry point is used for a module, and the module is compiled as an โ€˜ELFโ€™ binary, then kldload(8) fails to execute the entry point. ๐Ÿ’€
  • kldload(8) points the user to read dmesg(8) for any error encountered while loading a module. ๐Ÿ”
  • When system internal interfaces change, old modules often cannot detect this, and such modules when loaded will often cause crashes or mysterious failures. ๐Ÿšจ like, be careful.

okay bye bestie ๐Ÿ’– โ€” this page's footer says Debian, January 13, 2014, KLD(4). periodt. ๐ŸŽ€

๐Ÿ“ฆ where this page comes from