Customizing the FreeBSD Kernel
The kernel is the core of the FreeBSD operating system. It is responsible for managing memory, enforcing security controls, networking, disk access, and much more. While more and more of FreeBSD becomes dynamically configurable it is still occasionally necessary to reconfigure and recompile your kernel.
Because newer FreeBSD versions use dynamic modules, there is not a compelling need to recompile your kernel, unless you just don't like seeing that you are using the GENERIC kernel when you log in or do a uname. If you wish to compile your own kernel, please be careful and avoid commenting drivers out unless you really know what you are doing. If you wish to compile your own kernel, the following are the basic steps.
The following assumes that you selected the 'kernel developer' option when installing your FreeBSD system. If not, the easiest way to do this is by running sysinstall as root, choosing Configure, then Distributions, then src, then sys.
# sysinstall
Traditionally, the kernel name is in all CAPITAL LETTERS and, if you are maintaining multiple FreeBSD machines with different hardware, it is a good idea to name it after your machine's hostname. We will call it MYKERNEL for the purpose of this example.
# mkdir /root/kernels
# cp GENERIC /root/kernels/MYKERNEL
# ln -s /root/kernels/MYKERNEL
Now, edit MYKERNEL with your favorite text editor.
NOTE: Be sure and leave the line 'machine i386' alone and intact when defining your architecture.
You must now compile the source code for the kernel.
# /usr/sbin/config MYKERNEL
# cd ../compile/MYKERNEL
# make cleandepend; make depend
# make
# make install
The new kernel will be copied to the root directory as /kernel and the old kernel will be moved to /kernel.old. Now, shutdown the system and reboot to use your new kernel.
If you are having trouble building a kernel, make sure to keep a GENERIC, or some other kernel that is known to work on hand as a different name that will not get erased on the next build. You cannot rely on kernel.old because when installing a new kernel, kernel.old is overwritten with the last installed kernel which may be non-functional. So, copy kernel.old to kernel.safe with:
# cd /boot