Recompiling the kernel
The FreeBSD kernel can be recompiled in a number of simple steps. This may need to be done either while upgrading the system to a new version, to add support for various hardware not in the GENERIC kernel, or to change various kernel options. You cannot upgrade to a newer version of the kernel than the rest of the system. They must be upgraded together. This tight integration and coordination is one of the strengths of FreeBSD and contributes to its stability.
Overview of the steps in the process
The steps are as follows:
- Edit the kernel config file, copying it to a new name such as CUSTOM1
- Build the new kernel - make buildkernel KERNCONF=CUSTOM1
- Install the new kernel - make installkernel KERNCONF=CUSTOM1
- Reboot to test the new kernel
# su root
2. Copy the file /usr/src/sys/i386/conf/GENERIC to a new file such as /usr/src/sys/i386/conf/CUSTOM1
# cp /usr/src/sys/i386/conf/GENERIC /usr/src/sys/i386/conf/CUSTOM1
- Edit the new file using your favorite editor such as vi, emacs, or pico. Use a # to comment out lines, but still keep them in the file for later reference. Commented out options will not be built into the kernel.
# vi /usr/src/sys/i386/conf/CUSTOM1
- Look in the files /usr/src/sys/i386/conf/NOTES and /usr/src/sys/??? for the various options available to add into your custom kernel file.
# more /usr/src/sys/i386/NOTES
- Be careful which options or devices you remove from your custom config file. Don't remove any you don't understand, or at least read very carefully to learn which are needed to support others. If you remove too many and the kernel fails to build properly, assume the cause is you removed something you shouldn't have.
3. Change to the /usr/src directory to run the buildkernel command
- You may want to use the script command to save a record of the compile in case there are any errors to report or to read and learn more about the build proces.
# cd /usr/src # script build1 # make buildkernel KERNCONF=CUSTOM1
4. If the build process completes without errors, proceed to installing the kernel. It will automatically backup your old kernel for you. Then exit to end the scripting process, and finally reboot to test the new kernel.
# make installkernel KERNCONF=CUSTOM1 # exit # reboot
Now you're running a new custom kernel. Try editing a new config file and remove more things or add others. Some combinations will break things, so try again. That is a great way to learn about the kernel.