pavement

Kernel

From FreeBSDwiki
Revision as of 14:39, 17 September 2004 by Taxman (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The kernel is the core of the operating system that provides the basic services that programs need such as multi-tasking (process management), memory and virtual memory management, access to the filesystem, device drivers (or access to them), networking and interprocess communication.

The FreeBSD kernel is primarily a monolithic kernel meaning that most of its core services are tightly integrated and run in kernel space. It is also flexible in that it can be extended while running, with external modules using the kldload command. In a monolithic kernel, the services the kernel provides are made available through a set of system calls to programs that need to access them.

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

More detail

1. su to root or use sudo for every command

# 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 the 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/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.

Personal tools