# Loading Modules vs Compiling Kernel



## nickednamed (Oct 20, 2011)

While playing with and learning the basics of FreeBSD, I repeatedly wondered if I should compile a certain module into the kernel [EG pixel mode, VESA driver or network card driver] or have it loaded as a module in loader.conf.

The handbook lists the benefits or removing stuff from the kernel [IE faster boot time, less RAM usage]. 

But what are the advantages and disadvantages of compiling stuff into the kernel vs loading them as modules?

And can modules be removed by using an "include directive"? Or only added?


----------



## wblock@ (Oct 21, 2011)

Options (SC_PIXEL_MODE) have to be built into the kernel, kernel modules do not.  Modules are usually dynamic, able to be loaded or unloaded at any time.  If a module is built into the kernel, it can't be unloaded.


----------



## nickednamed (Oct 21, 2011)

Hmm. Seems I must have misunderstood something, somewhere along the line.

So what does a "stripped-down kernel" mean?

Does it mean a kernel with various "options" removed? [as opposed to modules]

And if so, I think one of my questions still remains: Is it possible to remove options from a kernel using an "include directive", or is it necessary to first strip down a kernel and then use the new stripped-down kernel as a base for others?

Sorry if these questions are a bit lame..


----------



## wblock@ (Oct 21, 2011)

nickednamed said:
			
		

> Hmm. Seems I must have misunderstood something, somewhere along the line.
> 
> So what does a "stripped-down kernel" mean?
> 
> Does it mean a kernel with various "options" removed? [as opposed to modules]



No, options (generally) control how modules are built.  For example, SC_PIXEL_MODE is an option for the syscons module.

A "stripped-down kernel" is one that has been built with fewer modules than the default GENERIC kernel.



> And if so, I think one of my questions still remains: Is it possible to remove options from a kernel using an "include directive", or is it necessary to first strip down a kernel and then use the new stripped-down kernel as a base for others?



It's easier than that.  include statements in kernel config files work pretty much like in other languages, just including the contents of another file.  So include GENERIC brings in all of the GENERIC kernel config file.  Then nodevice can be used to turn off all the modules that aren't needed.  See Simplifying FreeBSD Kernel Config Files for an example.


----------



## anomie (Oct 21, 2011)

@nickednamed: unless you have a special case that requires a custom kernel (and there are such cases), I'd discourage it. It's just one more thing you have to maintain across upgrades. As for supposed benefits: 

 How often do you reboot your system? (Well, possibly a lot if it's a laptop. I am thinking servers.) 
 How much RAM usage are you saving? Very little. (Don't take my word for it. Try a "stripped down" kernel and test.)


----------



## nickednamed (Oct 22, 2011)

Thanks guys!

Very informative. I had read that page you linked to before posting, but it will make more sense now. 

And bravo anomie! Miyamoto Musashi is indeed an interesting character with a lot of good things to say.


----------

