# Remove kernel drivers



## freejlr (Aug 11, 2021)

I am following the book "Absolute Freebsd" I suppose many of you will know it.

I'm in the chapter that talks about the kernel, where you can remove drivers and options that you don't need. Well I have the following problem and I can not understand why, (I am a newbie)

For example on my desktop system I don't need wireless support so I deleted the wlan device from the NOTES file of /usr/src/sys/conf with that I understood that when building a new kernel the wlan.ko module does not work. I would believe, but it is not like that, this is the output of my installkernel:

```
===> wlan (install)
install -T release -o root -g wheel -m 555   wlan.ko /boot/kernel/
install -T dbg -o root -g wheel -m 555   wlan.ko.debug /usr/lib/debug/boot/kernel/
===> wlan_acl (install)
install -T release -o root -g wheel -m 555   wlan_acl.ko /boot/kernel/
install -T dbg -o root -g wheel -m 555   wlan_acl.ko.debug /usr/lib/debug/boot/kernel/
===> wlan_amrr (install)
install -T release -o root -g wheel -m 555   wlan_amrr.ko /boot/kernel/
install -T dbg -o root -g wheel -m 555   wlan_amrr.ko.debug /usr/lib/debug/boot/kernel/
===> wlan_ccmp (install)
install -T release -o root -g wheel -m 555   wlan_ccmp.ko /boot/kernel/
install -T dbg -o root -g wheel -m 555   wlan_ccmp.ko.debug /usr/lib/debug/boot/kernel/
===> wlan_rssadapt (install)
install -T release -o root -g wheel -m 555   wlan_rssadapt.ko /boot/kernel/
install -T dbg -o root -g wheel -m 555   wlan_rssadapt.ko.debug /usr/lib/debug/boot/kernel/
===> wlan_tkip (install)
install -T release -o root -g wheel -m 555   wlan_tkip.ko /boot/kernel/
install -T dbg -o root -g wheel -m 555   wlan_tkip.ko.debug /usr/lib/debug/boot/kernel/
===> wlan_wep (install)
install -T release -o root -g wheel -m 555   wlan_wep.ko /boot/kernel/
install -T dbg -o root -g wheel -m 555   wlan_wep.ko.debug /usr/lib/debug/boot/kernel/
===> wlan_xauth (install)
install -T release -o root -g wheel -m 555   wlan_xauth.ko /boot/kernel/
install -T dbg -o root -g wheel -m 555   wlan_xauth.ko.debug /usr/lib/debug/boot/kernel/
```


I would also like to comment on more than one problem in this thread if you allow me, I have eliminated compatibility with 32-bit binaries and compatibility with previous FreeBSD, I have had compatibility problems such as with the Firefox browser, when opening the application it was turns into a crash.

I suppose it is normal, when removing said kernel options.

Regards.

EDIT:

The same with other modules such as linuxkpi.ko and firewire.ko all removed from NOTES and configuration files, but both compiled I have installed the new kernel.


----------



## SirDice (Aug 12, 2021)

freejlr said:


> For example on my desktop system I don't need wireless support so I deleted the wlan device from the *NOTES* file of */usr/src/sys/conf*


The NOTES file is just that, notes. It doesn't do anything with relation to building a kernel. It's just a file that contains everything that could _possibly_ be built. 

Something that always seems to trip up new users, everything is always built as a module. The kernel configuration just defines what gets  statically built-in in the kernel. If it's not statically linked into the kernel it can still be loaded as a module (for most things anyway).

Chapter 8. Configuring the FreeBSD Kernel


----------



## Geezer (Aug 12, 2021)

freejlr said:


> I am a newbie



I would suggest you do not build your own kernel. Or at least not yet and not unless really necessary.

Unlike much earlier versions of Freebsd, there is little need for a custom kernel, and not too much overhead of the GENERIC kernel. You will almost definitely be adding loadable modules rather than taking stuff out.



freejlr said:


> I am following the book



Dunno. [RHETORICAL]When was it written, what version was it written about?[/RHETORICAL]


----------



## freejlr (Aug 12, 2021)

SirDice said:


> The NOTES file is just that, notes. It doesn't do anything with relation to building a kernel. It's just a file that contains everything that could _possibly_ be built.
> 
> Something that always seems to trip up new users, everything is always built as a module. The kernel configuration just defines what gets  statically built-in in the kernel. If it's not statically linked into the kernel it can still be loaded as a module (for most things anyway).
> 
> Chapter 8. Configuring the FreeBSD Kernel



So that it is compiled and installed in the new kernel, does not mean that it is loaded?

I believed that when the kernel was loaded, all the kernel modules were loaded automatically.

Another example, I don't need sound on my machine, I eliminated the sound devices and more supports for sound cards, but as I said before, the sound.ko module was compiled, and I have it in my boot directory, in kernel.

I said that about the NOTES file, because in the .... / amd64 / conf file the LINT file includes if I'm not mistaken all these files in the kernel compilation.



> conf/NOTES
> x86/conf/NOTES
> NOTES





Geezer said:


> I would suggest you do not build your own kernel. Or at least not yet and not unless really necessary.
> 
> Unlike much earlier versions of Freebsd, there is little need for a custom kernel, and not too much overhead of the GENERIC kernel. You will almost definitely be adding loadable modules rather than taking stuff out.
> 
> ...



I thought it would be a good idea to remove modules that I do not need from the kernel, to avoid their load, however minimal, and in theory it would be safer to have fewer drivers loaded? I'm saying crazy user newbie. Can loaded drivers be exploited even though they are not in use by any device?

Maybe it is crazy what I am saying, and I am eliminating more than safe and tested modules, in reality I do not do it for that, simply because I want a module that I will never use.

The book is "Absolute FreeBSD The complete guide to FreeBSD 3rd edition" by Michael W. Lucas, 2019

Thanks guys.

EDIT:

I think I understood that the best reading I can do is the documentation of the handbook itself


----------



## SirDice (Aug 12, 2021)

freejlr said:


> Another example, I don't need sound on my machine, I eliminated the sound devices and more supports for sound cards, but as I said before, the sound.ko module was compiled, and I have it in my boot directory, in kernel.


It's not _in_ the kernel, it's now just a module you can load (kldstat(8), kldload(8)).


----------



## freejlr (Aug 13, 2021)

SirDice said:


> It's not _in_ the kernel, it's now just a module you can load (kldstat(8), kldload(8)).



If I understood it now, I did a test with my network interface by removing the device from the generic file, the driver was compiled and I installed in the kernel file, but in effect loading the kernel at startup does not load the driver of my controller EM next to the kernel.

As you explained to me well, it is no longer part of it, but as a module external to the kernel, as you can see in kldstat.



> Id Refs Address                Size Name
> 1   26 0xffffffff80200000  16665d8 kernel
> 2    1 0xffffffff81868000   67fd08 zfs.ko
> 3    1 0xffffffff81ee8000     9bc0 cryptodev.ko
> ...



The truth about the NOTES file has been stupid, if I even have the function of the file when reading it in the conf directory ... anyway.

I have some other doubts, but surely I can solve it myself, at least I will try. For example, the kernel options can be enabled / disabled as if it were a module?

Regards.


----------



## freejlr (Aug 16, 2021)

I see that it is not possible to attach new kernel options without creating a new one.

I already understood, for example I was reading chapter 8 about firewalls, and when starting the ipfw service, it loaded the ipfw module and the default rules. But when putting options IPFIREWALL in my kernel and compiling it, ipfw is loaded with the kernel and when starting the service it only loads the rules.

I'm going to read more the options file that is in the conf directory, I'm going to see what more options the kernel has, but being a noob I don't know what it can take advantage of.

The problem with firefox, was not that it deactivated the support for 32-bit binaries in the kernel, but that of previous FreeBSD.

COMPAT_FREEBSD4 to 12

Apparently firefox needs these options for its operation.

Regards.


----------



## SirDice (Aug 16, 2021)

freejlr said:


> Apparently firefox needs these options for its operation.


It probably only needs COMPAT_FREEBSD11 (and COMPAT_FREEBSD12 if you're on 13). On 12 a couple of important kernel structures where changed. A lot of software still hasn't caught up yet and are still using the version 11 structures. You can safely remove the COMPAT_FREEBSD4 to 10. Unless you plan on running really old binaries.


----------



## freejlr (Aug 18, 2021)

Reading the *options *file, I found an option about *LINT*.



> COMPILING_LINT



This option would compile the *NOTES *files obtaining a very large kernel. It is what I thought was happening from the beginning. Being a noob I did not find anything else that is useful for the moment, I think I will go to the next chapter.

It did not leave me anything about the configuration and compilation of the kernel? It just compiles the *DEFAULT *and *GENERIC *files from my amd64 directory.

If I leave any information, please tell me I don't like leaving the tasks incomplete.

Thanks.


----------

