FreeBSD Stable Release 6.0 Installer  Guide

Home______________________________________________________________________

 

Kernel Customizing

The kernel that comes with the FBSD install includes device statements for many of the most common devices on the market. It's very general on purpose so it will work for the majority of PC hardware configurations in public use. It's a rare occurrence when a FBSD system user never builds a custom kernel to fix problems or adds functions or hardware unique to their needs. Building a custom kernel is a normal process in the life of a FBSD system. If nothing else, just removing all the devices your particular system does not use will decrease the size of the kernel module causing it to load faster at boot time. As part of the basic FBSD install, FBSD provides a copy of the kernel source used to build the running kernel named GENERIC. Another kernel source named LINT contains all the kernel configuration statements with comments that are allowed in the kernel. The LINT file is your reference place where you would look for configuration statements for hardware devices or kernel options not in the GENERIC file. Please note the spelling of the names of these two files, Their names are in capital letters, and that's the way their file names are really spelled in the directory where they live.

Do not edit GENERIC directly, as it may get overwritten the next time you CVS update your kernel source and your kernel modifications will be lost. The GENERIC kernel config file lives in a directory which is five sub-directories deep. This becomes such a pain in the butt, typing in this long path every time you want to edit your custom kernel file. Your custom kernel config file is a very important element of your FBSD system. It should really live in the /etc directory with the other FBSD config files for easy backup. There is no reason your custom kernel config has to live in the same directory with GENERIC. It's a good idea to name your custom kernel config file after your machine's hostname= statement in rc.conf. You should call the new customized kernel config file 'gateway'.

 

Follow these instructions

cd /usr/src/sys/i386/conf        # point to correct directory

cp GENERIC /etc/kernel.gateway   # copy and rename to whatever you want

ln -s /etc/kernel.gateway        # create a link to itís new home

ee /etc/kernel.gateway           # edit your kernel source

Edit your gateway file making the changes you want. Feel free to change the comment lines at the top to reflect your configuration or the changes you have made to differentiate it from GENERIC.

 

Kernel Compile Steps

You must execute all of the following commands under the root account or you will get permission denied errors.

1. Change into this directory location (mandatory)

    cd /usr/src/sys/i386/conf

2. Run config program against kernel.gateway to generate the kernel source code.

    /usr/sbin/config kernel.gateway

3. Change into the build directory.

    cd ../compile/kernel.gateway

4. Issue compile commands

    make depend          # When this completes then issue next command

    make                 # When this completes then issue next command

    make install         # When this completes reboot to enable new kernel

Or combine all the single commands into one command line so all the make steps will run one after the other.

make depend && make && make install

As part of the "make install" process the current /boot/kernal/ directory is renamed to /boot/kernal.old/ then a empty /boot/kernal/ directory is populated  with the new kernal files. Now, reboot the system to use your new kernel.

 

Managing Multiple Kernels

FBSD only maintains the current kernel; in the default directory location /boot/kernel/, and the previous kernel; in the /boot/kernel.old/ directory location. After completing your first successful kernel compile the /boot/kernal.old/ directory holds the generic version of the kernel. It's common practice to make a copy of it to safe guard you ability to all ways be able boot your system.

mkdir /boot/kernel.generic/

cp -Rfv /boot/kernel.old/ /boot/kernel.generic/

Never delete the /boot/kernel.GENERIC/ directory. The /kernel.generic should be kept in case you compile a faulty kernel that won't boot properly and you need to boot from a kernel known to work. After you perform a couple of compiles in a row your original working kernel has rolled off and you have nothing to recover to.

Another common practice is to give special names to different kernels indicating what was added. Say in the current kernel you added IPFW statements to compile in IPfirewall. You should make a copy of /boot/kernel/ and give it a name that has meaning to you.

mkdir /boot/kernel.ipfw/

cp -Rfv /boot/kernel/ /boot/kernel.ipfw/

 

Replacing /kernel With Saved /kernel

Use these commands

cp -Rfv /boot/kernel.generic/ /boot/kernel   # replace kernel with different one

reboot      

 

Fix System Boot Problems

There maybe times when you have made changes to /etc/rc.conf or created a new kernel, and the FBSD will not boot successfully, or you forgot the root password.

You need to gain access to your FBSD system in some way so you can fix your problems. You do this be going into single user mode. This can only be done from the FBSD system console.

 

Single User Mode

During the normal boot process, it pauses for 10 seconds at the beastie menu. At this pause select option 4 for single user mode:

At the prompt for shell path, just hit enter on keyboard.

When the system comes up you have to manually mount all filesystems to gain access:

fsck -p

mount -u /

mount -a -t ufs

swapon -a

Now you have a running system as normal except you are the only one with access from the system console. Do whatever you need to do to repair your problem. When you have completed your repairs, enter the reboot command.

 

Forgot Root Password

During the normal boot process, it pauses for 10 seconds at the beastie menu. At this pause select option 4 for single user mode:

At the prompt for shell path, just hit enter on keyboard.

At the 'ok' prompt enter this commands

passwd root

and follow the prompts. When complete, enter the reboot command.

 

New Kernel Won't Boot

During the normal boot process, it pauses for 10 seconds at the beastie menu. At this pause select option 4 for single user mode:

At the prompt for shell path, just hit enter on keyboard.

At the 'ok' prompt enter these commands to load the GENERIC kernel or the kernel you want.

unload                 # unloads all modules that are positioned to boot from

load /boot/kernel.GENERIC/kernel   # Load the kernel you want or the generic one

boot                   # start the boot process over again using your kernel

______________________________________________________________________

This FreeBSD Installer Guide is an public domain HOW-TO.  This content may be reproduced, in any form or by any means, and used by all without permission in writing from the author.