Skip to main content
Topic: Automatically loading kernel module during boot (Read 6351 times) previous topic - next topic
0 Members and 1 Guest are viewing this topic.

Automatically loading kernel module during boot

Hi all,

this is my first post so before I move to the question I would like to thank the developers for creating Artix Linux.
Until this summer I used Manjaro-Openrc on several computers and moved smoothly to Artix Linux. On my
other computers I run Devuan, Void, Alpine and FreeBSD. So I am 100% systemd-free.

Now to the real question. I have Artix Linux on a HP laptop with an Ethernet card and I have determined
that I need to use the kernel module r8169. I have added this module in the file /etc/conf.d/modules
with the line
Code: [Select]
modules="r8169"
but after boot, my Ethernet card does not seem to exist. At least, it is not reported by
Code: [Select]
sudo ifconfig -a

If I load the module manually with
Code: [Select]
sudo modprobe r8169
the interface then shows up as enp3s0 and I can start the network with
Code: [Select]
sudo rc-service net.enp3s0 start

So I cannot figure out what is going wrong with the module. Am I doing something wrong?
Also, how can specify that the module must be loaded before the corresponding service
is started?

Re: Automatically loading kernel module during boot

Reply #1
On Arch-based distros, you're going to want to use mkinitcpio to load modules. Edit /etc/mkinitcpio.conf and add it in the modules line.
Code: [Select]
modules="r8169"

After that, rebuild the initramfs. If you use the lts kernel, run:
Code: [Select]
# mkinitcpio -p linux-lts

If you're on a different kernel, just replace "linux-lts" by whatever the name is (i.e. "linux", "linux-ck", etc.)

Re: Automatically loading kernel module during boot

Reply #2
Thanks for your help.

I haven't solved the problem yet but here is what I found so far.

In the default /etc/mkinicpio.conf the modules variable is in capitals, so I used that.

Module r8169 uses module mii. Both are loaded automatically by modprobe but I added mii to MODULES just to be sure
it is loaded. So I had the line
Code: [Select]
MODULES="mii r8169"
in /etc/mkinitcpio.conf and ran
Code: [Select]
sudo mkinitcpio -p linux-lts
I verified that this is the kernel that gets loaded by grub. Indeed, there is a file /boot/vmlinuz-linux-lts and that is also the file that is referenced in my grub menu entry. In the same entry, the initrd image /boot/initramfs-linux-lts.img is used.

When I boot, the interface still does not come up. The module mii is loaded but the module r8169 is not. Again, running
Code: [Select]
sudo modprobe r8169
solves the problem.

Also, as far as I can remember, I did not have this problem when I was using manjaro-openrc. The problem appeared after I migrated to Artix. Maybe something has broken during the migration?

Re: Automatically loading kernel module during boot

Reply #3
I put my 5 cent and maybe that my hint is absolutely unusable, but: is not that you have to "dkms" the module?

I did the same with the realtek 8192 chip and all work correctly.


Re: Automatically loading kernel module during boot

Reply #4
eudev - udev rules?
modules-load or modprobe line in the service script as a workaround?

Re: Automatically loading kernel module during boot

Reply #5
In the default /etc/mkinicpio.conf the modules variable is in capitals, so I used that.

Ah yes, that's correct. Sorry I forgot about that. Is that module somehow blacklisted by any chance? Do you have any configuration files in /etc/modprobe.d/ that blacklist it? Or maybe you're loading another module that automatically blacklists it?

Re: Automatically loading kernel module during boot

Reply #6
eudev - udev rules?
modules-load or modprobe line in the service script as a workaround?

that is not a good idea.  That only works if the autoloading is working in the first place, the correct modules are compiled and all the system space machinery is working, which it seems to not at this juncture.

I'm wondering if he is adding the correct module version to the ram disk.  Also, I am confused by unix4evers answer.  He is describing how to add modules to the initial boot image, which is not even strictly necessary for booting.  It gets swapped out once the system is booted up and then his modules should autoload as the system continues to boot up and brings up networking and services through openrc. 

I think his trouble is in demod
http://www.tutorialspoint.com/unix_commands/depmod.htm

Re: Automatically loading kernel module during boot

Reply #7
@unix4ever
have you some output error message with dmesg command?
Anyway i think about firmware trouble, something like this https://packages.debian.org/wheezy/firmware-realtek, but you need to invest to find it for arch
Obarun : free to control your system

Re: Automatically loading kernel module during boot

Reply #8
Yes, mrbrklyn, I think udev loads kernel modules but the chipsets they are associated with are set elsewhere. Although if unix4ever can modprobe the module and his ethernet works then I don't think modprobing it automatically would be dangerous, but it would be a suboptimal solution. So I suggest trying:
sudo lspci -vvv
which should give more info. Try before modprobing and see if another kernel driver is listed for the ethernet device, sometimes another one needs blacklisting. Also look at the chipset number and see if it is mentioned in here:
https://github.com/torvalds/linux/blob/master/drivers/net/ethernet/realtek/r8169.c
Otherwise it might not be automatically detected (I think that would be where the list of supported chipsets for the module is found).
While I was looking for the above page I came across this one (although the guide was for Ubuntu):
https://unixblogger.com/2016/08/11/how-to-get-your-realtek-rtl8111rtl8168-working-updated-guide/
so I understand what francesco was saying now about dkms
 There might be a better driver available that is not installed by default.

Re: Automatically loading kernel module during boot

Reply #9
You who remains nameless :)

udev can not reach into kernel land (thank god for small miracles) and Linus would indeed have a fit it did. 

https://unix.stackexchange.com/questions/330186/where-does-modprobe-load-a-driver-that-udev-requests#330209



The uevent message contains information about the device (example). This information contains registered vendor and model identification for devices connected to buses such as PCI and USB. Udev parses these events and constructs a fixed-form module name which it passes to modprobe. modprobe looks under /lib/modules/VERSION for a file called depmod.alias which is generated when the kernel is installed and that maps the fixed-form module names to actual driver module file names. See Are driver modules loaded and unloaded automatically? for more details about the process — that answer describes the earlier days when the kernel called modprobe directly, but the way modprobe and module aliases work hasn't changed.

See also Michael Opdenacker's presentation “Hotplugging with udev” which has more examples and describes other aspects of device management with udev, and the Linux from scratch guide which has a section on how the fixed-form module names are defined.

modprobe loads a module by calling the init_module system call. It doesn't interact with sysfs in any way. When the module is loaded, the kernel creates an entry for it in /sys/module. Any entry that appears elsewhere in sysfs is up to the code in the module (e.g. a module with a driver for a type of USB devices will call some generic USB support code that adds an entry under /sys/bus/usb/drivers).


Re: Automatically loading kernel module during boot

Reply #11
To autoload your modules, put them in /etc/conf.d/modules or /etc/modprobe.d/modname.conf.

This gave me the right hint to solve the problem. Adding the module to /etc/conf.d/modules did not change anything, but when I looked at the other directory I found a file /etc/modprobe.d/r8169_blacklist.conf with the line
Code: [Select]
blacklist r8169
in it. I just removed the file and everything worked fine. If I understand correctly, the module is chosen by udev(?)

Also, I noticed that the date of /etc/modprobe.d/r8169_blacklist.conf is 28th July 2017. This should be about the time I migrated manjaro-openrc to Artix. Can it be that the file was created automatically during the migration? If so, I wonder why.

Anyway, problem solved! Thanks a lot for the help!

Re: Automatically loading kernel module during boot

Reply #12
spot on.  This is now old news for kernel development and universal for all distros