# Kernel options for static ZFS?



## Orum (Jun 17, 2012)

I've been looking several places (man pages, handbook, forums, mailing lists, etc.) for what options (or devices) are needed in the kernel configuration to statically compile in ZFS support.  Currently I'm on 9.0-RELEASE, and loading ZFS at boot time (root is ZFS), and I see two modules are loaded, zfs.ko and opensolaris.ko.

Is it possible to compile these in so I don't need to load the modules?  And if so, what do I need in my kernel config?

Edit: Seems a `kldstat -v` gives some clues to what might be needed.

```
zfs.ko (/boot/kernel/zfs.ko)
        Contains modules:
                Id Name
                 3 zfsctrl
                 4 zfs
                 6 zfs_vdev
                 5 zfs_zvol
opensolaris.ko (/boot/kernel/opensolaris.ko)
        Contains modules:
                Id Name
                 1 opensolaris
```
So, do I need device entries for all of these?


----------



## phoenix (Jun 18, 2012)

No, it is not possible to compile ZFS into the kernel.


----------



## Orum (Jun 18, 2012)

Ah, that's unfortunate.  Any particular reason why?  Licensing?


----------



## phoenix (Jun 19, 2012)

I believe it's licensing-based, but don't know for sure.  For a definitive answer, you may need to post the question on the freebsd-fs@ mailing list.


----------



## quickthyme (Jul 22, 2018)

For anyone looking at this in 2018, the answer is still no. It is due to licensing reasons, so harass Oracle. The only operating systems currently in production that have native ZFS built-in to the kernel are those based on Solaris. (OS/Net, Ilumos, etc)


----------



## PMc (Jul 22, 2018)

phoenix said:


> No, it is not possible to compile ZFS into the kernel.





quickthyme said:


> For anyone looking at this in 2018, the answer is still no.



Beg You pardon?
ZFS is normally compiled into the kernel. Only if one wants to get dtrace and drm2 and linux etc. also compiled in, then one has to twiddle with /usr/src/sys/conf/ a bit. (I don't know if this is "allowed". I probably didn't ask.)


----------



## ShelLuser (Jul 23, 2018)

PMc said:


> Beg You pardon?
> ZFS is normally compiled into the kernel.


It's not. This is also why you need to edit /boot/loader.conf in order to make things work:

```
zfs_load="YES"
```
...and why kernel modules such as zfs.ko and opensolaris.ko exist in GENERIC.



PMc said:


> Only if one wants to get dtrace and drm2 and linux etc. also compiled in, then one has to twiddle with /usr/src/sys/conf/ a bit.


Uhm, no?

Not every feature which is provided as a kernel module can be build statically into the kernel. In fact, most features cannot and fully rely on kernel modules, eventually there really isn't much difference between a kernel module or an embedded feature on FreeBSD.

Also note that /usr/src/sys/conf isn't the right location to configure your kernel, config(8) isn't really used anymore to build / configure. Instead use /usr/src/sys/<arch>/conf as also explained in Chapter 8.4 of the FreeBSD handbook.


----------



## PMc (Jul 23, 2018)

ShelLuser said:


> It's not. This is also why you need to edit /boot/loader.conf in order to make things work:
> 
> ```
> zfs_load="YES"
> ...



Well, then:


```
root # zpool list
NAME   SIZE  ALLOC   FREE  CKPOINT  EXPANDSZ   FRAG    CAP  DEDUP  HEALTH  ALTROOT
bm     804G   564G   240G        -         -    34%    70%  1.00x  ONLINE  -
gr    50.5G  19.5G  31.0G        -         -    36%    38%  1.00x  ONLINE  -
root # kldstat
Id Refs Address    Size     Name
1    1 0x80400000 d4297c   kernel
root # grep zfs /boot/loader.conf
vfs.zfs.trim.enabled="0"
vfs.zfs.arc_max="800M"
vfs.zfs.arc_min="200M"
vfs.zfs.prefetch_disable="1"
root # uname -r
11.2-RELEASE
root #
```



> Uhm, no?
> 
> Not every feature which is provided as a kernel module can be build statically into the kernel. In fact, most features cannot and fully rely on kernel modules, eventually there really isn't much difference between a kernel module or an embedded feature on FreeBSD.



Well, there may be some difference as soon as you try to backtrace a kernel crash and it doesn't find the proper files...

And yes, this is not a GENERIC kernel; its a custom build.


----------



## ShelLuser (Jul 23, 2018)

PMc said:


> And yes, this is not a GENERIC kernel; its a custom build.


As such my point stands; ZFS isn't normally build into the kernel.

In fact most options within FreeBSD are usually provided through kernel modules. One of the reasons being that there eventually isn't much difference between linking in a module or loading it afterwards. If you run `kldstat -v` you'll notice that it mentions "_Contains modules:_" and eventually lists zfs again. It never stopped being a module.


----------



## PMc (Jul 23, 2018)

ShelLuser said:


> As such my point stands; ZFS isn't normally build into the kernel.
> 
> In fact most options within FreeBSD are usually provided through kernel modules. One of the reasons being that there eventually isn't much difference between linking in a module or loading it afterwards. If you run `kldstat -v` you'll notice that it mentions "_Contains modules:_" and eventually lists zfs again. It never stopped being a module.



Sure it does, it reports zfs as "contained in the kernel" - which is exactly the point of the exercise: there are no modules loaded via kldload.
I just checked my logs: i have this in the kernel-configs since Rel .11.1:
`options         ZFS`
And this seems to work out of the box.

I also have these in the kernel-config:
`device          dtrace
device          dtraceall
device          drm2
device          i915drm`
But these probably don't work without modifying some files.


----------



## usdmatt (Jul 23, 2018)

I'm intrigued. What are the reasons behind wanting to compile ZFS into the kernel?


----------



## PMc (Jul 23, 2018)

At some time I had to debug some issues, and I found that the debugger would not always find the source files from loaded modules. 
Instead of searching the flaw in the debugger, I decided to simply not have loaded modules.


----------



## UnitedMarsupials (Sep 13, 2021)

usdmatt said:


> I'm intrigued. What are the reasons behind wanting to compile ZFS into the kernel?


So as not to, when switching kernels at boot-time, worry about compatibility of modules. That is, your kernel may be from /boot/kernel.old, but the modules will still be from /boot/kernel -- and not necessarily compatible.

Using modules makes sense, when they are for a rarely-used feature -- such as, mounting a FAT-formatted storage. For everything, that you use _all the time_ -- such as, usually, ZFS -- you'll want to have it in kernel...


----------



## Argentum (Sep 13, 2021)

UnitedMarsupials said:


> So as not to, when switching kernels at boot-time, worry about compatibility of modules. That is, your kernel may be from /boot/kernel.old, but the modules will still be from /boot/kernel -- and not necessarily compatible.
> 
> Using modules makes sense, when they are for a rarely-used feature -- such as, mounting a FAT-formatted storage. For everything, that you use _all the time_ -- such as, usually, ZFS -- you'll want to have it in kernel...


This seems to be a very old thread, but now with 13.0 I can see that there is a short note in /usr/src/sys/amd64/conf/NOTES

```
#####################################################################
# ZFS support

# NB: This depends on crypto, cryptodev and ZSTDIO
options         ZFS

#####################################################################
```

I have not tried this yet, but hope it works...


----------



## hardworkingnewbie (Sep 13, 2021)

usdmatt said:


> I'm intrigued. What are the reasons behind wanting to compile ZFS into the kernel?


The main reason would be improving security by being able to totally disable kernel modules. To do so, ZFS needs to be compiled into the kernel. 

Disabling module loading or even removing kernel modules altogether like OpenBSD did removes one major attack vector for security breaches.


----------

