# Compiling Statically Linked Kernel



## criswell (Jul 17, 2012)

Dear All,

I was wondering if it's possible to compile a FreeBSD kernel that is statically linked (i.e., all device drivers and modules are compiled into the kernel as opposed to being loaded dynamically).

I've assumed that listing devices in the kernel configuration file compiles the device driver as a separate, dynamically loadable module.  Is this assumption incorrect?

Thanks in advance for any advice,

-- John T.


----------



## kpa (Jul 17, 2012)

Anything that can exist as a loadable kernel module is first compiled as a module.  Listing a driver in the kernel configuration file then causes it to be linked statically into the kernel binary and it can not be unloaded at run time. If you want a monolithic kernel that doesn't need loadable modules you just list all needed drivers in the configuration file.


----------



## SirDice (Jul 18, 2012)

criswell said:
			
		

> I've assumed that listing devices in the kernel configuration file compiles the device driver as a separate, dynamically loadable module.  Is this assumption incorrect?


It's the other way around. Anything that is not in the kernel configuration file is compiled as a module.


----------



## fluca1978 (Jul 19, 2012)

SirDice said:
			
		

> It's the other way around. Anything that is not in the kernel configuration file is compiled as a module.



Just a curiosity: this also means that the whole code base is compiled (either as module or statically), and therefore the only way to avoid the compilation of an unwanted and unused feature is to remove the code from the codebase?


----------



## SirDice (Jul 19, 2012)

Have a look at MODULES_OVERRIDE, NO_MODULES and WITHOUT_MODULES in make.conf(5). Other parts of the base OS can be turn on or off using src.conf(5).


----------

