Want to speed up your system a bit as well as reduce boot time and resource usage? Or compile extra features into your kernel? The best way to do that is to compile your own custom kernel yourself. It is much simpler than you would think, ESPECIALLY if you’ve ever tried it in Linux. 😉
- A FreeBSD system (I’m using 4.7, though I am sure this would apply to 5.x as well.)
- Make sure that you have installed kernel sources and development tools when you installed your system, if not, you can always pop your CD back in and install them by using /stand/sysinstall
Log in or su to root
# cd /usr/src/sys/i386/conf # ls
You will see two files, GENERIC and LINT. GENERIC is the configuration file for the kernel you are currently running and will create a kernel to run on almost any machine. LINT contains every possible configuration option for the kernel. We will concern ourselves with GENERIC for the moment.
First you want to make a copy of GENERIC and give it a name of your own. For this guide we will just call it EXAMPLE.
# cp GENERIC EXAMPLE
Open up EXAMPLE with your favorite text editor. The first part of what you will see looks like this:
machine i386 cpu I386_CPU cpu I486_CPU cpu I586_CPU cpu I686_CPU ident GENERIC maxusers 0
This lists the classes of processors that the kernel will be compiled for as well as IDENT, which you can put at whatever you want, and MAXUSERS which is used for performance tuning (just leave it at zero and it will be handle automatically). You will want to comment out (a # placed in front of the line) every cpu line except for the class of processor that you are running (ie: I586_CPU=Pentium class, I686_CPU=Pentium II/III/Athlon class and above). Make sure NOT to comment out your class, or your kernel won’t boot. Also, DO NOT TOUCH the machine string.
Go down through the file and add any options that you wish to add into your kernel (assuming you know what your doing), and comment out stuff that you don’t need. For example, if your not using SCSI you can comment out all the SCSI device lines, and the lines for NICs that your not using. Now be careful with the NICs, if your interface shows up as, say, xl0 and you comment out device xl then you might just want to stick with Windows. You can also safely comment out anything related to IPv6, INET6, FAITH, and GIF. You’re not going to need those for a long time, if ever with this system. Also, if you are not sure what something is, there is usually an explanation next to it with a brief description. More detailed descriptions can be found in LINT.
After you have finished commenting out what you don’t need and adding what you want, save EXAMPLE and exit your text editor. It is now time to configure and build your kernel.
# config EXAMPLE
It will do its little thing, takes maybe a couple minutes on most machines, and will give you this nice little message:
Don't forget to do a "make depend" Kernel build directory is ../../compile/EXAMPLE
Now switch to the build directory and build the dependencies:
# cd ../../compile/EXAMPLE # make depend
This will take a little while, go get a soda, have a smoke, whatever you do to pass time. When it is done you will be dumped back to the command prompt.
It is now time to actually build and install the kernel.
# make all install; make clean
Now this will take a good bit of time, a couple of hours on older systems, less time on newer systems, only 20 minutes or so on my 733 Athlon classic. But there are many variables that will affect this. Go take a nap.
When you come back the new kernel will be compiled and installed (barring any screw-ups), and all you have to do is reboot.
# shutdown -r now
If everything is fine, your system will boot just fine and be perfectly usable. Congratulations, you’re done! Go have a drink.
If the system halts during boot or the kernel panics, then you made a boo-boo. Hard reset the computer (the reset button). The bootloader will give you the option to enter custom boot settings. I forget exactly what it says, but it’s pretty obvious. Just type boot kernel.GENERIC and it should load the system normally. Then just figure out what you screwed up, fix it, rebuild and install the kernel, and hope for the best.
If you need more help you can find me in #Beowulf or #freebsd on the SqueakNet IRC network (irc.squeaknet.net).