FreeBSD  Release  11.0  Install  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. There are 2 other sources of kernel configuration statements that are allowed in the kernel. These files are your reference places where you would look for configuration statements for hardware devices or kernel options not in the GENERIC file. They are /usr/src/sys/i386/conf/NOTES and /usr/src/sys/conf/NOTES. Please note the spelling of the names of these 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. There is no reason your custom kernel config has to live in the same directory with GENERIC. 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. It's a good idea to name your custom kernel config file after your machine's hostname= statement in rc.conf. We will 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/

2. Compile the kernel

    make buildkernel KERNCONF=kernel.gateway

3. Install the new kernel

    make installkernel KERNCONF=kernel.gateway

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

make buildkernel KERNCONF=kernel.gateway && make installkernel KERNCONF=kernel.gateway

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 your ability to all ways be able to boot your system.

mkdir /boot/kernel.generic/

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

Or you can just rename the boot/kernel.old/

mv /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

Rename the directories

mv /boot/kernel/ /boot/kernel.bad/

mv /boot/kernel.generic/ /boot/kernel/

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 FreeBSD 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 FreeBSD menu. At this pause select option 4 for single user mode:

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

Follow the instructions in the "Single User Mode" above.

Then enter this command

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 FreeBSD menu. At this pause select option 6 for Escape to loader prompt:

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.XX/kernel   # XX = the name of the kernel directory
                              # you want to load. kernel.old for kernel
                              # previously compiled or kernel.generic
                              # if your saved it previously.

boot        # start the boot process over again using your kernel

 

Previous Page                                        Next Page         

This FreeBSD Install 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.