Building FreeBSD Custom Kernel

Small Tips on how to build kernels faster

According to FreeBSD Handbook, there are two ways of building a custom kernel: The Traditional Way and The New Way.

Either way, we should create a custom kernel configuration file, Then we use this custom kernel configuration for building the new kernel:

$ cd /usr/src
$ cp sys/amd64/config/GENERIC sys/amd64/config/CUSTOM

For example, we can enable kernel debuggings enabled in our custom configuration:

$ cat >> sys/amd64/config/CUSTOM <EOF
makeoptions -g
options KDB
options DDB
EOF

Now, to compile the new kernel with our custom configuration:

make -j 16 buildkernel KERNCONF=CUSTOM
make -j 16 installkernel KERNCONF=CUSTOM

If you're experiencing modifying kernel and trying to avoid re- compiling the kernel every time you have a small change in the source code, use the following command:

make -j 16 buildkernel KERNCONF=CUSTOM -DKERNFAST

Tips: Remember to remove the multiple make jobs -j flags if you have errors in compiling the source to easily spot the error message:

make buildkernel KERNCONF=CUSTOM -DKERNFAST