modprobe

package
v1.14.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: MPL-2.0 Imports: 26 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package modprobe implements the kernel modprobe usermode helper: it loads a kernel module on demand.

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAModule = errors.New("not a module name")

ErrNotAModule is returned when the requested name is not a module shipped with the running kernel.

This is the expected outcome for subsystem aliases (e.g. 'fs-xfs', 'net-pf-10', 'crypto-aes'), which are what userspace can trigger via mounts, sockets, etc.: Talos never loads modules via aliases.

Functions

func Main

func Main(args []string)

Main is the entrypoint into /sbin/modprobe as invoked by the kernel usermode helper (request_module()).

The kernel executes the static usermode helper (machined) as `/sbin/modprobe -q -- <module>` and waits for the process to exit, so the module is loaded by the time Main returns.

The helper runs as root in the initial namespaces, so it loads the module itself: the module name is looked up without resolving aliases (see LookupModule), and the parameters come from the machine config (KernelModuleSpec resources read via the machined API) if the module is listed there.

Like `modprobe -q`, a request for a name which is not a module exits with an error silently.

func ModuleNameFromArgs

func ModuleNameFromArgs(args []string) (string, bool)

ModuleNameFromArgs extracts the module name from the modprobe arguments.

The kernel invokes `modprobe -q -- <module>`: options (arguments starting with '-') before '--' are skipped, the first argument after '--' or the first non-option argument is the module name.

func NormalizeModuleName

func NormalizeModuleName(name string) string

NormalizeModuleName converts the module name to the form used by the kernel ('-' and '_' are interchangeable).

func ParametersFor

func ParametersFor(specs []*runtime.KernelModuleSpec, name string) []string

ParametersFor returns the parameters of the module from the machine config (KernelModuleSpec resources), if listed.

Module names are matched in the normalized form, so the config might list the module as 'dm-thin-pool' while the kernel requests 'dm_thin_pool'.

func QuietFromArgs

func QuietFromArgs(args []string) bool

QuietFromArgs reports whether the quiet option ('-q') is present among the modprobe options.

func ValidModuleName

func ValidModuleName(name string) bool

ValidModuleName checks that the name is syntactically a kernel module name.

func VerifyKernelParent

func VerifyKernelParent(ppid int, procfsPath string) error

VerifyKernelParent checks that the process with the given PID is a kernel thread.

The kernel spawns the usermode helper from a kernel thread (kthreadd or a kworker), while any process started from userspace has a userspace parent (orphans are reparented to init or a subreaper, never to a kernel thread), so a kernel thread as the parent proves the request was issued by the kernel.

Types

type Lookup

type Lookup int

Lookup is the outcome of looking up a module name in the modules directory.

const (
	// LookupNotFound means there's no such module (the name might be an alias, which is not resolved).
	LookupNotFound Lookup = iota
	// LookupBuiltin means the module is built into the kernel.
	LookupBuiltin
	// LookupLoadable means the module is available to be loaded.
	LookupLoadable
)

func LookupModule

func LookupModule(modulesDir, name string) (Lookup, error)

LookupModule looks the module name up in modules.builtin and modules.dep of the modules directory.

Aliases (modules.alias) are deliberately not consulted: kernel code requesting another module (e.g. a driver loading a helper module while probing a device) uses the module name, while subsystem aliases (net-pf-*, fs-*, crypto-*, binfmt-*, ...) are what userspace can trigger via sockets, mounts, etc.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL