# which modules inside kernel are actually used on my system?



## antolap (Nov 4, 2017)

If I do `kldstat -v` I see all modules pre-built inside default kernel installed on my system.

How do I know which of them are used/needed for my pc and which of them not?


----------



## da1 (Nov 4, 2017)

I don't know of any direct approach but an indirect one would be checking the drivers in your dmesg and their corresponding kernel module(s). For instance, if you have an Intel EtherExpress Pro/100 Mbit NIC (fxp) in your dmesg, a `man fxp` would reveal the modules the kernel needs.

Case in point:

```
[root@xxx 2:10pm] ~/>grep fxp /var/run/dmesg.boot
fxp0: <Intel 82559 Pro/100 Ethernet> port 0xe8c0-0xe8ff mem 0xfe102000-0xfe102fff,0xfe000000-0xfe0fffff irq 16 at device 8.0 on pci0
miibus1: <MII bus> on fxp0
fxp0: Ethernet address: 00:b0:d0:79:28:45
fxp0: link state changed to UP
fxp0: link state changed to DOWN
[root@xxx 2:10pm] ~/>kldstat -v|grep fxp
                130 pci/fxp
                131 fxp/miibus
```


----------



## ShelLuser (Nov 4, 2017)

Ayups, that's how I approach things whenever I'm customizing my kernel. /var/run/dmesg.boot is your friend there. However, do be careful because it's not full proof.

There are also modules being loaded because others depend on them. A notable example of that could be smbfs which will automatically pull in libiconv and libmchain. Sometimes those dependencies can be tricky to find, I remember this one from mind because I had major problems with a custom kernel (it wouldn't load the smbfs.ko module) and eventually I studied the source code.

When looking into /usr/src/sys/fs/smbfs/smbfs_vfsopts.c I eventually spotted this:


```
MODULE_DEPEND(smbfs, netsmb, NSMB_VERSION, NSMB_VERSION, NSMB_VERSION);
MODULE_DEPEND(smbfs, libiconv, 1, 1, 2);
MODULE_DEPEND(smbfs, libmchain, 1, 1, 1);
```
Which cleared up that problem for me.

Of course this will only become an issue if you chose to use MODULES_OVERRIDE to control which kernel modules should be build.


----------

