Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm curious:

What, exactly are the benefits to statically linking modules into the kernel rather than loading through rc.conf, etc?

For example:

To add linux emulation, I could add linux_enable="YES" to /etc/rc.conf, or I could link it into the kernel by adding options COMPAT_LINUX to my kernel config.

Is there actually an advantage to this? If so, what?

share|improve this question
up vote 2 down vote accepted

Statically linking used to be the only way to load a module which is think is the primary reason to having options like COMPAT_LINUX. Also, prior to loader, it used to be the only way to load modules necessary to get FreeBSD to get the necessary drivers to mount the root file system and boot FreeBSD. Nowadays, I don't think there is any significant benefit to statically linking in a module if it can be easily loaded at runtime. I don't think you will see any benefit in performance by statically linking Linux compatibility support, but some users still swear by it. I would avoid it just because of the inconvenience of recompiling a Kernel for little to no perceived performance gain.

share|improve this answer
    
Perfect. It's what I assumed, and I'd much rather edit a conf file than recompile whenever I add new support :P – Demian Brecht Apr 20 '11 at 19:35
  1. If you statically link everything you need you can then simply use "makeoptions NO_MODULES=yes" so you're not building unnecessary modules.

This can also be accomplished with MODULES_OVERRIDE and/or WITHOUT_MODULES.

  1. The ability to load modules at runtime is not always a good thing. The module could be a rootkit for instance.

SECURELEVEL also mitigates this.

As with these two, probably any benefit can also (and some would argue, should) be accomplished in another way.

Personally I like my kernel to be like a firewall ruleset: I start by excluding everything, then add what I need and prevent additions at runtime.

Unless the kernel is recompiled, I know exactly what is supported. So if I have not compiled in some functionality, like SCTP or NFS, I can just ignore advisories that only affect those parts. Adding functionality requires me to manually add it.

With modules there are numerous ways how a module could get loaded automatically: by simply using some functionality once, by installing a port, by updating (default changed, new functionality added), etc.

In all of those cases I think it's a benefit to be forced to manually add the functionality if, and only if, it's actually needed.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.