Is it possible to dynamically load (via MOD_ALIAS() maybe?) a module that requires another module to first be loaded?
Background: I have a USB->I2C bridge on my system, and attached to the i2c end is a touchscreen. The kernel module that brings up the i2c automatically loads/unloads whenever the USB cable is connected/disconnected. I'm looking for a way to also load/unload the touchscreen driver on the same events.
You're talking about module dependencies, generated by depmod -A. The actual dependency information is stored in /lib/modules/version/modules.dep.
If /lib/modules/2.6.29/kernel/a.ko depends on b.ko (in the same directory) you could add the line:
/lib/modules/2.6.29/kernel/a.ko: /lib/modules/2.6.29/kernel/b.ko
To create the dependency.
What you want is modprobe.d
Add a <module>.conf file where <module> is the name of your kernel module that is dynamically loaded.
Define the install and remove options within the above conf file to run the relevant commands instead of the modprobe (in the required order).
If you want to automatically load the module bob after loading the module alice,
# /etc/modprobe.d/alice.conf
install alice /sbin/modprobe --ignore-install alice; /sbin/modprobe bob;"
The --ignore-install, stops the modprobe from running the same install command again.
Similarly define the remove section within the same conf file.
For more details, checkout the man page of modprobe.d.
Related
I'm building the Qlogic fibre channel adapter kernel module to use with scst. The kernel module that gets created is named qla2xxx_scst.ko. Is there some option on the make command line that can be used to change the kernel module name or the "scst" part of the kernel module name at compile time?
For example, I want to create qla2xxx_test.ko instead of qla2xxx_scst.ko.
I don't want to change the source file names either.
When I run make all in the qla2xxx directory the resultant make command line that runs is:
make -C /lib/modules/4.15.0-91-generic/build SUBDIRS=/home/niverson/test/scst-qlogic/qla2xxx BUILD_INI=m
That appears to run the Makefile completely from /lib/modules/4.15.0-91-generic/build and I don't want to modify those default make scripts either.
I have found posts saying to modify the obj-m and xxxxx-objs lines in the qla2xxx directory Makefile to rename the kernel module, but those didn't seem to work since the qla2xxx directory Makefile just runs the command line above.
I'm working with a raspberry pi connected with xrusb to a controller using python.I use make file to Compile and install the common usb serial driver module and it works fine. After reboot i have problem. The driver is lost. I have to install the module again using this
modprobe usbserial
insmod ./xr_usb_serial_common.ko
Any idea?
Now my answer might be off because of the way you say "install the driver". I bet the make script most likely just loaded the driver just like you did via modprobe.
In order to get the module to be loaded at boot time, you need to tell udev what to load/do during bootup. And tell the kernel to load your driver.. Otherwise it assumes you don't want it to be loaded at boot time.
Either you can do a automatic module handling via:
#nano /etc/modules-load.d/usbserial.conf
usbserial
or, you can specify options:
#nano /etc/modprobe.d/usbserial.conf
options usbserial parameter_name=parameter_value
Here's some documentation on how this works:
http://man7.org/linux/man-pages/man5/modules-load.d.5.html
https://wiki.archlinux.org/index.php/kernel_modules
(Even if you're not running Arch on your RPi, they still have one of the best documentation websites for Linux out there. User friendly, in depth etc. So apply the information there to your Distribution, they should be very much the same this day and age)
I found maybe a temporary solution so i can finish my project and look for the best way later.
I make a script to run after reboot to load the driver.
use:
sudo crontab -e
then go to the bottom and write
#reboot bash /your/path/script/script.sh
`
I'm doing some development on a GPU kernel module. It gets compiled only on 'make modules' and not on 'make', so I can say it is a dynamically loaded module that loads on Linux boot. I would like to rapidly recompile and reinstall the module without installing a whole new kernel. Is it ok to simply 'make modules' and then replace the existing .ko file in /lib/modules/... and then reboot? If not (perhaps it is in use) can I boot into a different kernel, do the replacement, and reboot back in? Is it possible even to just insmod it?
It gets compiled only on 'make modules' and not on 'make', so I can say it is a dynamically loaded module that loads on Linux boot.
You should check where the module is placed. It can be stored only in /lib/modules/...kernel-version../, or in /lib/modules and inside initramfs (initrd). In second case you need regenerate initramfs image after updating ko in /lib/modules.
I would like to rapidly recompile and reinstall the module without installing a whole new kernel. Is it ok to simply 'make modules' and then replace the existing .ko file in /lib/modules/... and then reboot?
Yes, this is allowed to change .ko file, even when module is loaded. (Loading of the module with init_module is done from in-memory copy of .ko ELF file, so used version of module will still use old data).
On reboot you will have all modules and their files unused too.
Is it possible even to just insmod it?
It is not allowed to do insmod of module which is already loaded (compared by name - check EEXIST error in man finit_module). You may try to load it with different name, but older module has ownership of hardware and newer module will have no access to PCI/PCIe device.
So, you should unload older module by rmmod modulename before inserting newer version. Unloading is possible only for unused modules (man delete_module, check usage counter in lsmod output) - there should be no other modules depending on your, no processes should use it. After unloading you can do insmod modulename.ko or modprobe modulename.ko.
Reboot will unload older module and load newer module.
In case of GPU driver you should stop the X.org server and stop system console which uses graphics too (so, you can't switch to text console and reload gpu module interactively; it can be done remotely with ssh or with shell script with unbind/unload/load), check this question https://askubuntu.com/questions/418296/fastest-way-to-reload-graphics-driver-module
sudo /etc/init.d/lightdm stop
echo 0 > /sys/class/vtconsole/vtcon1/bind
I compiled my Linux kernel according to the Linux Device Driver Chapter 4: Debugging Techniques. After I loaded my first hello world module and then checked the output by dmesg, however, all I can see is evbug: ........
I know I can turn off evbug's output by execute sudo rmmod evbug. But, obviously, it is inconvenient to execute this command after each reboot.
How could I disable this module's autoloading? I just want to load it manually when I need it.
You need to blacklist the module. For debian systems see https://wiki.debian.org/KernelModuleBlacklisting. For redhat systems see https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html/Installation_Guide/rescuemode_drivers-blacklisting.html
Is there a way to list down from command line the complete dependency list of kernel modules loaded in the kernel at runtime?
Let me clarify my question a little bit.
What I am trying to do:
I get a list of all loaded modules using lsmod
Then remove/unload currently loaded kernel modules by running a loop. I am using modprobe -r. This step fails (obviously) as some modules are in use.
(I can switch to using rmmod -r, but don't want to as it is unsafe and can crash the system.)
Then I want to load the modules one by one again.
It is step 2 that is failing, as I cannot get all the module dependencies before using modprobe -r.
Any ideas, suggestions or comments ?
However lsmod o/p is sometimes incomplete. It also does not always indicate all the modules dependent on a given module.
What you see in lsmod in the "Used by" column are merely the static symbol dependencies that you can also look at using modinfo.
If however a piece of kernel code takes a reference on a module using (try_)module_get, the caller will not be recorded. References do not have an owner (moduleA could pass the pointer to moduleB, which then module_puts it..), there is nothing to record for the Used by column.
To get a list of module dependencies as would be used by modprobe (i.e. this should normally be the full list, but see the answer by user502515), use
$ modprobe --show-depends <module>
Note that this command shows more information than modinfo's depends: line, as it lists dependencies recursively (i.e. dependencies of dependencies).
It also takes into account alias commands in modprobe configuration files.
Tested using:
$ modprobe -V
kmod version 14
man lsmod: lsmod is a trivial program which nicely formats the contents of the /proc/modules, showing what kernel modules are currently loaded.
Edited:
see also: depmod -n