In this blog I will not talk about hints. That might come in a later blog.
Also I will take the opportunity to promote the FreeBSD handbook. I really suggest that you learn how to use it because it is really simple. It's not hard with a lot of unnecessary text, but very straight on. I suggest that you always go and read the handbook before google any problem you might have. I usually solved my problems the other way around, which gave me more problems since those blogs were about older versions of the kernel and so forth. The subject that is interesting for you to read about today is Configuring the FreeBSD kernel.
Make sure you have root access, preferably by logging in as regular user and:
- Execute: su (and enter password)
- Execute: cd /usr/src/sys/i386/conf (You might want to change i386 for your particular architecture.)
- Execute: mkdir /root/kernels (This will create a directory in your root home folder)
- Execute: cp GENERIC /root/kernels/MYKERNEL (where you change MYKERNEL to whatever you like, usually your machine name)
- Execute: ln -s /root/kernels/MYKERNEL (this creates a symbolic link from the actual file in your /root/kernels directory into the /usr/src/sys/i386/conf directory)
Now you have the basics setup. What we just did was making a copy of the GENERIC kernel configuration into your root home folder. Then we linked that file up into the conf folder. The reason why we did this is actually so that we can delete the /usr/src folder if we like, without being afraid that we loose our custom kernel configuration.
Lets edit the configuration file with the ee editor, we have had enough of VI for now:
- Execute: ee /root/kernels/MYKERNEL
If you scroll through the file you might notice that at the beginning it's all about options, then further down we have devices. Notice on the second line from the top, it sais "GENERIC" and a short description. Change that to whatever you like. It doesn't have any functional meaning but it just feels right to do it.
- Find three lines that looks like this cpu
- Comment out any line that doesn't match your CPU. (My CPU is a Pentium 4 2.8 GHz HyperThreading. So I comment out I486 and I586 and keep I686)
Kernel identification, I'm not sure what this is good for. But it feels right to update.
- Find the line that begins with "ident"
- Change GENERIC to MYKERNEL (or whatever you called it before)
I like to turn off debugging aswell. I'm not sure if it has any effect on the FreeBSD Kernel but it usually do have a positive performance effect on other software så I suggest that you comment out debugging.
- Find line makeoptions DEBUG=-g and comment it out
Now lets see what we might want to add to the kernel.
- options NETATALK # AppleTalk, because I like Apple so mouch
- options IPFILTER # Enable statefull Firewall
# Note: The IPF can be enabled
# as a loadable module in rc.conf
# with ipfilter_enable="YES"
If you are looking for other options, then I suggest that you take a look inside /usr/src/sys/i386/conf/NOTES because this file has the list of all options available for the kernel.
Now perhaps you want to optimize your kernel. Scroll through all the device rows in the file and comment out any device not available for your system. Remember that some of the devices is not optional. Example the miibus device is a must have if your NIC is one of those that is dependent upon that device. Both of my NIC:s is. Just read the comments and you will be fine.
Now that you have your own kernel configuration just hit ESC and press A to Exit ee and A again to Save and Exit.
- Execute: cd /usr/src/
- Execute: make buildkernel KERNCONF=MYKERNEL
- Wait for it...
- Wait for it...
- Wait for it...
Now you might have experienced either a complete compilation or you have a compiler error. If you have a error then you have probably left a device that is dependent of a device that you have removed. Try from the error message to understand what devices it's about and then figure out if you should remove or add a device to the kernel.
If everything is fine then you
- Execute: make installkernel KERNCONF=MYKERNEL
Okay, your kernel is now installed and will be used next time you reboot!