Linux kernel: Difference between revisions
imported>Jiehong mNo edit summary |
imported>Tobias.bora No edit summary |
||
Line 120: | Line 120: | ||
$ dmesg | grep hello | $ dmesg | grep hello | ||
[ 82.027229] hello world! | [ 82.027229] hello world! | ||
</syntaxHighlight> | |||
== Load modules in the kernel == | |||
As far as I understand, if you developped a kernel module, you should end up with having some `.ko` files inside a subfolder inside `$out/lib/modules/${kernel.modDirVersion}`. Now, if you want to make your module loadable inside the kernel by `modprobe`, you should do: | |||
<syntaxHighlight lang=nix> | |||
boot.extraModulePackages = [ yourmodulename ]; | |||
</syntaxHighlight> | |||
Then, the user can load it using: | |||
<syntaxHighlight lang=console> | |||
$ sudo modprobe yourmodulename | |||
</syntaxHighlight> | |||
or unload it using | |||
<syntaxHighlight lang=console> | |||
$ sudo modprobe -r yourmodulename | |||
</syntaxHighlight> | |||
However, if you want to autoload your module at startup in stage 2, you need to do: | |||
<syntaxHighlight lang=nix> | |||
boot.kernelModules = [ "yourmodulename" ]; | |||
</syntaxHighlight> | |||
and the module will be automatically loaded after a reboot. If you want instead to load it at stage 1 (before the root is even mounted), you need to add it to `boot.initrd.availableKernelModules` and `boot.initrd.kernelModules`. | |||
Note that if you don't reboot, you can still load manually the module using `modprobe yourmodulename`, and to automatically enable a module during configuration switch/reboot, you can put `modprobe yourmodulename || true` inside the script of a systemctl service (it is for example what does wireguard). | |||
Finally, if you want to define some options by default (used when you load manually a module using `modprobe`, or when the system boots), you can specify them in: | |||
<syntaxHighlight lang=nix> | |||
boot.extraModprobeConfig = '' | |||
options yourmodulename optionA=valueA optionB=valueB | |||
''; | |||
</syntaxHighlight> | </syntaxHighlight> | ||