# prevent kernel building a built in module



## Pegasus711 (Jan 16, 2021)

Hello friends

I'm trying to experiment a bit with NIC drivers on my VM and would like the kernel to not auto load `if_em.ko` but it just won't stop loading it. Is there a way to do that? In my custom kernel config file, I have commented out
`device em`
but when I check after building `/boot/kernel`, `if_em` still seems to get built. Am I missing something? I have also update `/etc/make.conf` with
`WITHOUT_MODULES=if_em`
but to no avail.

Awaiting your suggestions


----------



## Speedy (Jan 16, 2021)

See make.conf(), there are a few variables to address this.


----------



## Pegasus711 (Jan 16, 2021)

Well, I've used WITHOUT_MODULES but it doesn't seem to work as intended. And there have been threads on mailing lists saying the same (I wonder if they've made it work now). Is there something else one can try?


----------



## Speedy (Jan 16, 2021)

I've used MODULES_OVERRIDE myself for long time and it always worked for me. Never tried WITHOUT_MODULES, though.


----------



## Pegasus711 (Jan 16, 2021)

With MODULES_OVERRIDE I need to make sure all modules that are *actually* needed to run my HW are present. I really wished WITHOUT_MODULES would work


----------



## Speedy (Jan 16, 2021)

Don't know, I have everything I need built into kernel and I have only two modules (which I load only when I need them).


----------



## Pegasus711 (Jan 17, 2021)

Well good for you but in my own case, I need to watch some stuff at driver load so this is not an option. I wished there was an option similar to the 'M' option in the Linux kernel alas it looks there isn't (correct me if I am wrong)


----------



## Speedy (Jan 17, 2021)

Maybe there is. I recall many years ago I added a bunch of IPFIREWALL options into my kernel by hand so they got built into kernel instead of being modules. They were not in GENERIC, unfortunately I do not remember what documentation I was reading at the time.

Back to your issue, if you do not want it loaded just move it, then next boot it won't be found. Move it back if you want to use it again. Renaming it probably will work, too.


----------



## memreflect (Jan 17, 2021)

I suspect you want `WITHOUT_MODULES=em`, and you can use `nodevice em` in your kernel config instead of commenting `device em`; `nodevice em` is required if your kernel config contains `include GENERIC` since GENERIC on multiple architectures contains `device em`.

From the 8.4 The Configuration File of the FreeBSD Handbook:


> An `include` directive is available for use in configuration files.  This allows another configuration file to be included in the current one, making it easy to maintain small changes relative to an existing file.  If only a small number of additional options or drivers are required, this allows a delta to be maintained with respect to GENERIC, as seen in this example:
> 
> ```
> include GENERIC
> ...



config(5) states that `device XXXX` would build support for XXXX into the kernel image, and `nodevice XXXX` removes support for XXXX.

make.conf(5) states that `WITHOUT_MODULES` prevents creation of the modules, but what it doesn't mention is that you need to use the device names in the kernel config, not the name of the resulting module (e.g. `WITHOUT_MODULES=em`, not `WITHOUT_MODULES=if_em`).  I found that last bit of info through trial and error, first building using `WITHOUT_MODULES=if_em` (fail) and then using `WITHOUT_MODULES=em` (success).

I realize this is a lot of information for what are essentially two very simple changes, but I wanted to illustrate how I found that information in the first place, so that others might benefit from the process in the future.


----------

