# How to compile kernel modules separately and manuelly?



## xiaoj (Aug 28, 2009)

I used MODULES_OVERRIDE to decide which modules be compiled with kernel compilation. But maybe sometimes I need some mudule compiled and installed by hand. 

Is there some method to compile and install kernel modules separately and manuelly? not rebuild the kernel and modules already installed in /boot/kernel, but compile and install the only one specified module.


----------



## SirDice (Aug 28, 2009)

They all have a directory in /usr/src/sys/modules/. You can try doing a make from one of them.


----------



## anemos (Aug 28, 2009)

FreeBSD supports two types of kernel modules:

 - Permanent modules 

 - Loadable modules 

Loadable modules are not statically linked into the kernel. Instead they are loaded at run-time. 
See kldload(8) and kld(4)
If you want to write your own kernel module then module(9) might help.


----------



## xiaoj (Aug 29, 2009)

Thanks anemos, the module what i mean is just the loadable modules, I have not enough c skill to be able to write my own module, what i need recently is some command to compile and install one loadable module separately and manuelly.

Thanks a lot.


----------



## anemos (Aug 29, 2009)

Then, as SirDice pointed out, go to /usr/src/sys/modules/module_name, run 
	
	



```
$ make
$ kldload module_name.ko
```

You can see the loaded module with

```
$ kldstat
```


----------



## SIFE (Dec 5, 2009)

i think it is like this :

```
kldload ./module_name.ko
```


----------



## Wasp (Oct 19, 2017)

Time passes but the problems are somehow similar...
"Where" to build modules which are not in /usr/src/sys/modules but are (also) modules obviously and how to build them? For ex. stuff under /usr/src/sys/dev/usb/wlan.
Even more specific: How to rebuild if_urtwn.ko only?


----------



## tobik@ (Oct 19, 2017)

Wasp said:


> Time passes but the problems are somehow similar...
> "Where" to build modules which are not in `/usr/src/sys/modules` but are (also) modules obviously and how to build them? For ex. stuff under `/usr/src/sys/dev/usb/wlan`.


They have corresponding directories in /usr/src/sys/modules/usb/.


----------

