FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

modprobe, kmodule: support Linux kernel module autoloading by brho · Pull Request #3767 · u-root/u-root · GitHub

/ u-root Public

modprobe, kmodule: support Linux kernel module autoloading - #3767

Open
brho wants to merge 2 commits into
u-root:mainfrom
brho:master
Open

brho wants to merge 2 commits into
u-root:mainfrom
brho:master

Conversation

brho commented Sep 30, 2026

Copy link
Copy Markdown

When the Linux kernel autoloads a module via request_module(), call_modprobe() in kernel/module/kmod.c invokes:

/sbin/modprobe -q -- <module_or_alias>

with PATH=/sbin:/usr/sbin:/bin:/usr/bin. Previously this failed in u-root for several reasons:

  • /sbin/modprobe did not exist (busybox binaries live in /bbin).
  • modprobe did not support -q or unixflag parsing, and unixflag.ArgsToGoArgs rewrote '--' to '-' while continuing to split subsequent arguments as flags.
  • kmodule did not resolve module aliases from modules.alias, modules.symbols, modules.builtin.modinfo, or modprobe.d/.conf (e.g. fs-9p -> 9p, 9p-fd -> 9pnet_fd, symbol:, or modalias wildcards).

Fix these and related issues in modprobe and pkg/kmodule:

  • Create /sbin and a /sbin/modprobe -> /bbin/modprobe symlink in libinit.
  • Fix unixflag.ArgsToGoArgs to stop flag splitting on '--' and '-'.
  • Update cmds/exp/modprobe to use unixflag and support -q/--quiet, -r/--remove, -b/--use-blacklist, -i/--ignore-install/--ignore-remove, -v/--verbose, -a/--all, -n/--dry-run/--show, -d/--dirname, -S/--set-version, and '--'. Reuse a single Prober across -a/-r arguments and exit non-zero on -a errors.
  • Resolve aliases from modprobe.d/*.conf, modules.alias, modules.symbols, and modules.builtin.modinfo, including wildcard globs, bracket ranges, DMI '/' dates, and chained aliases with cycle detection.
  • Parse module options and blacklists from modprobe.d/*.conf (/etc, /run, /usr/local/lib, /usr/lib, /lib with filename override precedence) and /proc/cmdline (.= and modprobe.blacklist=...).
  • Support softdep (pre: and post:) from modules.softdep and modprobe.d/*.conf, and treat 'Loading' modules in /proc/modules as in-kernel so recursive request_module() calls during module_init do not deadlock.
  • Support module removal (Prober.Remove / modprobe -r) in reverse topological order, skipping dependencies still in use by other loaded modules.
  • Fix findModPath for module filenames mixing '-' and '_', genLoadedMods early abort on out-of-tree modules, genDeps parsing of blank/comment lines and trailing spaces, and modStack slice aliasing in parallelProbeDep.

Assisted-by: LLM

brho requested a review from rminnich September 30, 2026 20:29

brho commented Sep 30, 2026

Copy link
Copy Markdown
Author

gemini did this one. let's see how the tests go.

codecov Bot commented Sep 30, 2026 •
edited
Loading

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.75862% with 67 lines in your changes missing coverage. Please review.
✅ Project coverage is 61.91%. Comparing base (8c86aab) to head (8389851).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3767      +/-   ##
==========================================
+ Coverage   61.46%   61.91%   +0.45%     
==========================================
  Files         648      648              
  Lines       45716    46349     +633     
==========================================
+ Hits        28099    28698     +599     
- Misses      17617    17651      +34     
Flag Coverage Δ
.-amd64 90.90% <ø> (ø)
cmds/...-amd64 52.70% <96.84%> (+0.31%) ⬆️
integration/generic-tests/...-amd64 28.38% <0.15%> (-0.98%) ⬇️
integration/generic-tests/...-arm 30.23% <0.15%> (-1.53%) ⬇️
integration/generic-tests/...-arm64 27.17% <0.15%> (-0.92%) ⬇️
integration/gotests/...-amd64 61.15% <90.75%> (+0.60%) ⬆️
integration/gotests/...-arm 61.46% <90.75%> (+0.89%) ⬆️
integration/gotests/...-arm64 61.34% <90.75%> (+0.56%) ⬆️
pkg/...-amd64 59.95% <89.84%> (+0.84%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
everything 66.75% <89.84%> (+0.33%) ⬆️
cmds/exp 35.29% <96.84%> (+0.98%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

brho force-pushed the master branch 3 times, most recently from 4f94abe to 6acf690 Compare October 1, 2026 20:55
Comment thread pkg/libinit/root_linux.go Outdated

Dir{Name: "/etc", Mode: 0o777},

// The kernel's modprobe_path defaults to /sbin/modprobe for

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

This is not really how we want to do this, because, sometimes, the u-root initramfs is merged into an existing ramfs. We don't want to overwrite it this way.

I would suggest using the -base option with a cpio consisting of these two files. There may be other ways, but the change as done here can not be used.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

that's unfortunate - without some other initramfs, you won't be able to use module autoloading. and it's a pain to have to manually modprobe stuff.

not sure how exactly the extra cpio will work in our build environment. (possibly related: i've had other problems with our stuff and e.g. default_shell not setting a symlink for bin/sh).

other alternatives are changing the kernel config for it, (which is largely a non-starter), or changing the modpath at init time (which is potentially racy).

anyway, i'll have my agent talk to your agent to remove that symlink...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

actually, this is easy to add via command line
mkdir sbin
ln -s //sbin/modprobe sbin
u-root bla bla -files sbin

That's it. That's all it takes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

note you can put that sbin anywhere
mkdir /tmp/blablah/sbin
ln -s /sbin/modprobe /tmp/blabla/sbin
u-root bla bla -files /tmp/blabla/sbin:sbin

you can create a tmpdir or whatever you want.

rminnich added the Awaiting author Waiting for new changes or feedback for author. label Oct 1, 2026
When the Linux kernel autoloads a module via request_module(), call_modprobe()
in kernel/module/kmod.c invokes:

  /sbin/modprobe -q -- <module_or_alias>

with PATH=/sbin:/usr/sbin:/bin:/usr/bin. Previously this failed in u-root for
several reasons:
- modprobe did not support -q or unixflag parsing, and unixflag.ArgsToGoArgs
  rewrote '--' to '-' while continuing to split subsequent arguments as flags.
- kmodule did not resolve module aliases from modules.alias, modules.symbols,
  modules.builtin.modinfo, or modprobe.d/*.conf (e.g. fs-9p -> 9p,
  9p-fd -> 9pnet_fd, symbol:*, or modalias wildcards).

Fix these and related issues in modprobe and pkg/kmodule:
- Fix unixflag.ArgsToGoArgs to stop flag splitting on '--' and '-'.
- Update cmds/exp/modprobe to use unixflag and support -q/--quiet, -r/--remove,
  -b/--use-blacklist, -i/--ignore-install/--ignore-remove, -v/--verbose,
  -a/--all, -n/--dry-run/--show, -d/--dirname, -S/--set-version, and '--'.
  Reuse a single Prober across -a/-r arguments and exit non-zero on -a errors.
- Resolve aliases from modprobe.d/*.conf, modules.alias, modules.symbols, and
  modules.builtin.modinfo, including wildcard globs, bracket ranges, DMI '/'
  dates, and chained aliases with cycle detection.
- Parse module options and blacklists from modprobe.d/*.conf (/etc, /run,
  /usr/local/lib, /usr/lib, /lib with filename override precedence) and
  /proc/cmdline (<mod>.<param>=<val> and modprobe.blacklist=...).
- Support softdep (pre: and post:) from modules.softdep and modprobe.d/*.conf,
  and treat 'Loading' modules in /proc/modules as in-kernel so recursive
  request_module() calls during module_init do not deadlock.
- Support module removal (Prober.Remove / modprobe -r) in reverse topological
  order, skipping dependencies still in use by other loaded modules.
- Fix findModPath for module filenames mixing '-' and '_', genLoadedMods early
  abort on out-of-tree modules, genDeps parsing of blank/comment lines and
  trailing spaces, and modStack slice aliasing in parallelProbeDep.

Assisted-by: LLM
Signed-off-by: Barret Rhoden <brho@google.com>
brho requested a review from rminnich October 2, 2026 10:29
brho added Awaiting reviewer Waiting for a reviewer. and removed Awaiting author Waiting for new changes or feedback for author. labels Oct 2, 2026

This branch has not been deployed

No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Awaiting reviewer Waiting for a reviewer.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants


Back | FazBrowse Home | New Git URL