# Proper way to block a list of modules to autoload?

## sylware

Since module autoloading is handled by udev and the modprobe blacklist keyword does concern only module aliases, what is the proper way to block a specific module to load  :Question: 

----------

## DocReedSolomon

 *sylware wrote:*   

> Since module autoloading is handled by udev and the modprobe blacklist keyword does concern only module aliases, what is the proper way to block a specific module to load 

 

by not even compiling it in the first place?

----------

## sylware

Well, that's for nvidia drivers. I would like to disable autoloading for the kernel module *the proper gentoo way* when I develop stuff for Xorg. Since this issue is not specific to nvidia kernel module, I asked for the general case.

----------

## sylware

udev OPTIONS assignement key does support ignore_device and last_rule options. This is probably the answer.   :Embarassed: 

----------

## albright

 *Quote:*   

> udev OPTIONS assignement key does support ignore_device and last_rule options. This is probably the answer. 

 

I'm glad you figured that out - would you mind enlightening the rest

of us how you tell udev to blacklist a particular set of modules? TIA.

----------

## sylware

Everything is detailed in the man page.

I have not tried yet since I use in my specific case the rmmod command.

But you would add a line before the driver modules autoload rules to your udev rules file similar to this one:

```
ACTION=="add", DRIVER=="nvidia", OPTIONS="ignore_device,last_rule"
```

----------

## albright

thanks for that (giving an example is great - the

udev man page has no examples, so it is about

as clear as mud how you actually construct

the rules ... there ought to be a law: all man pages

contain a set of examples)

----------

## sylware

Actually, the previous example does not work. When udev is coldplugging it seems to have no idea of the name of the module to load. It seems to be done by modprobe. But modprobe module blacklisting does not work for module name and only alias.

So you must not think like "blocking a module to load" but like "blocking modules to load for a specific device".

For instance, on my system which has a nvidia board on the AGP slot, lspci tells me the PCI location of this board: 0000:00:01.0

So in order to block coldplug related to this pci device (in fact it's an AGP board), I added to /etc/udev/rules.d/50-udev.rules:

```
DEVPATH=="*0000:00:01*",OPTIONS="ignore_device,last_rule"
```

I have not looked at udev and modprobe code, then this workaround could be brain damaged.

----------

## albright

thanks for that - I had noticed the first suggestion made no difference

The problem with the second suggestion is that while it prevents

the loading of the module at boot up it prevents operation after

modprobing. For example, after udev-rules are modified according

to your suggestion, ipw2200 does not load at boot. After a modprobe

ipw2200, iwconfig reports "no such device"  :Sad: 

----------

## sylware

I tested it with the nvidia module and it does work. Namely, I can modprobe nvidia and the module is properly loaded, and as expected the module is not cold plugged.

You should only test the availability of the ipw2200 module stack only with the lsmod command.

More over, I'm not sure of that, but the udev rules may be processed sequentially. I put my rule as the first of the "module autoload" section. You can find this "section" in /etc/udev/rules.d/50-udev.rules searching for "module autoload" string. It may help.

Additionally, you could enable debug log and verbose ouput for udev in order to discover what exactly happens at boot for cold plug on your system (in /lib/rcscripts/addons/udev-start.sh). You also have the udevmonitor --env command which may help you to understand a bit better how udev works.

----------

## Pajarico

I have a question about this issue. I want lirc support to be loaded at boot but also want the serial module (8250 and related) compiled because sometimes I need them. I wrote a rule to load lirc before 8250, so when 8250 tries to load the kernel will realize that there is already the lirc_serial module in control of the serial port. This rule is called 10-lirc.rules, and goes after 05-udev-early.rules, which should make the trick. The actual result is that 8250 gets loaded and even un if I do a rmmod and modprobe lirc_serial it won't work. Why?

 *sylware wrote:*   

> Actually, the previous example does not work. When udev is coldplugging it seems to have no idea of the name of the module to load. It seems to be done by modprobe. But modprobe module blacklisting does not work for module name and only alias.
> 
> So you must not think like "blocking a module to load" but like "blocking modules to load for a specific device".
> 
> For instance, on my system which has a nvidia board on the AGP slot, lspci tells me the PCI location of this board: 0000:00:01.0
> ...

 

About your example how would you guess whats is the DEVPATH to the serial port? lspci doesn't list it.

----------

## sylware

Never tried for non PCI devices (and actually other things than the nvidia ugly kernel module).

As far as I understood it at the time, the udev module coldplug does concern only PCI device. I may be wrong, it has been a long time.

----------

## Pajarico

If udev only cares about PCI devices, who is modprobing the modules for serial port?

----------

## sylware

Had a look at the 50-udev rules.

You have to understand the rules file in order to see if the serial module gets loaded (check out the pnp modules). Also keep in mind that your module may be loaded as a requirement of another module (kernel module audoloading).

----------

## Pajarico

Thanks. But 50-udev rules doesn't tell me anything interesting. There is no mention of the modules 8250, 8250_pnp or 8250_pci. There is a section for serial devices but nothing interesting in there, mouses, keyboards, mentions to tty devices... but in my limited knowledge of udev nothing seems related to the serial modules. So what is loading them? Nothing is loading them as a dependency as 8250 needs *_pnp and *_pci but nothing calls 8250... so?

----------

## sylware

Try to debug udev or something like that, ask on irc some help.

Have a look at the kernel source.

----------

## dch24

This post describes the difference between 'blacklist' and what you are trying to do:

 *Joey Hess wrote:*   

> Package: module-init-tools
> 
> Version: 3.3-pre11-1
> 
> Severity: normal
> ...

 

In other words, this will disable it at the modprobe level. (Then when you want to use it, just add a # to comment out the line, and run update-modules and modprobe it in. Not exactly what you wanted, but ...)

There's a good discussion in the bug #130766 thread about using /etc/conf.d/rc to disable services (so the modules are still loaded but the service doesn't get started) and about the security hole opened by autoloading evbug. The bug is closed because "Comment  #46 From Matthias Schwarzott  2007-02-13 00:16:10 0000  [reply] udev-104-r11 (and -r10) implement the wrapper-based blacklisting, by using the blacklist-lines from modprobe.conf" but I have not seen documentation or an example of how this works.

----------

