Print View

Compile a Custom Kernel
Created: 10/05/2006


General Information

There may be two main reasons as to why you would want a custom kernel on your system: 1) You want to add some functionality to your system such as audio support, or 2) you may want to remove some unused drivers to conserve memory.

Either way, making a custom kernel will help your machine to be a faster box rather than using the GENERIC kernel.

Requirements

  1. A FreeBSD system (5.x or greater)
  2. Your favorite text editor

Installation

We will want to use sysinstall to get the src:
# sysinstall
  1. select Configure
  2. select Distributions
  3. select src
  4. select sys (/usr/src/sys (FreeBSD Kernel))
  5. press Enter
  6. press Enter
  7. select CDROM (Or choose FTP if you chose NOT to install from CDROM)
  8. select Install
This will take a few minutes to install via CDROM.

Configuration

Once you have the source installed we can then start on the kernel customization:
# cd /usr/src/sys/i386/conf
This is where FreeBSD keeps its kernel configuration files for Intel computers.  The generic kernel config is in the file GENERIC.  All the possible kernel options can be found in the NOTES file.  What we will want to do first is copy GENERIC to a new Kernel name.

Note:  *NEVER* edit the GENERIC file.

# cp GENERIC MYKERNEL
A few notes about editing your new kernel file:

1) Here is an example line from the kernel
device          ppbus           # Parallel port bus (required)
Any line that says (required) means exactly that.  Don't comment it out or delete it.  So in this example, you can delete everything below that section if you don't have a Printer, TCP/IP over parallel, or a Parallel port interface device.

2) Don't delete any lines.  Comment them out with a # in the front.

3) Always change your ident line as follows

Scroll down the line that reads:
ident GENERIC
Change the line to read:
ident MYKERNEL
4) If you're not sure what you have or don't have for devices, you can check this in /var/log/messages (provided it hasn't been forever since your last reboot).

This is a great example.  There are a ton of Network Card drivers in the kernel and you really only need one.  Let's look in /var/log/messages for your Ethernet Card.  I'll use my NIC as an example:
fxp0: <Intel 82559 Pro/100 Ethernet> port 0xec00-0xec3f mem 0xdf100000-0xdf100fff,0xdf000000-0xdf0fffff irq 11 at device 9.0 on pci0
So if we edit MYKERNEL and scroll down to the PCI and make sure you keep the following lines in there and comment everything else in the PCI and ISA Network card sections:
device          miibus          # MII bus support
device          fxp             # Intel EtherExpress PRO/100B (82557, 82558)
So go ahead and make all the changes from there.

Once you are done, it's time to compile the kernel.
#
#
cd /usr/src
make buildkernel KERNCONF=MYKERNEL
If you get some errors you screwed up.  Go fix it or copy GENERIC back to MYKERNEL and start over.  If not, you can continue by installing the kernel.
# make installkernel KERNCONF=MYKERNEL
You are done!  You should reboot to make the changes effective!

After the reboot you should see that you are on the new kernel.
# uname -a
FreeBSD beast.local x.x-XXXXX FreeBSD 6.X-XXXXX #0: Day Mon XX XX:XX:56 EDT 2006
USER@beast.local:/usr/obj/usr/src/sys/MYKERNEL  i386


Author: Bill
wolson at gmail dot com



12 Comments

Posted by jimd on November 28, 2006 at 11:56:31 pm EET

Can you copy a kernel to a new install from an existing install?
Thanks,
jim


Posted by w0ls0n on November 29, 2006 at 12:21:36 am EET

It depends. If you did a fresh install of the OS and it's on the same hardware, then the answer is yes. Just copy your /usr/src/sys/i386/conf/KERNEL file first before the fresh install.

If it's another PC you're installing to, its possible the kernel will still work but it's really based on the hardware. Generally what I like to do is start with a fresh kernel and just compare the hardware detected in /var/log messages or dmesg with the new kernel.

Hope that helps. Let me know if you have any other questions.

Bill
http://freebsdrocks.net
http://goodcleanemail.com


Posted by jimd on November 29, 2006 at 12:26:14 am EET

It would be a fresh install on new hardware, but the hardware is exactly the same as the existing install.  I have a production box and a test box, the production box is FreeBSD 6.1 and the test box is FreeBSD 5.4.  I am looking for the best way to make the test box exactly the same as the production box, except for the id information.  I figured I'd have to start with the kernel and then copy the rest of the partitions.  Am I on the right track?
Thanks for your help, I'm a Windows admin with relatively little FreeBSD experience, but I'm not afraid of the command line.  I have at least compiled my own kernel before.
Thanks,
jim


Posted by w0ls0n on November 29, 2006 at 1:07:28 am EET

Why not use 6.1 on both? 5.4 is a bit outdated and 6.1 is much better in my opinion. I wouldn't suggest taking the 6.1 kernel and copying it to the 5.4 box. That just wouldn't be a good idea. Being a windows admin myself for about 10+ years I know how you feel there. :-) As far as copying the partitions, what exactly are you looking to copy? If you're just copying your files from your /home dir, vpopmail or maybe your www folder, you can use my backup vpopmail doc. You can basically use it to copy anything from a server to another server or backup server. It uses a combination of ssh and rsync. Take a look at

http://www.goodcleanemail.com/kb.php?ToDo=view&questId=56&catId=5

If you're ever on the freenode IRC server, join channel #qmr and I will most certainly be able to help. I am on there Mon - Fri 9-4.

Again, let me know if you have any questions of problems.

Bill
http://freebsdrocks.net
http://goodcleanemail.com


Posted by jimd on November 29, 2006 at 3:49:56 pm EET

I want to have 6.1 on both, I actually want both servers to be exactly the same, aside from IP address and name.  That's why I was hoping I could somehow get a shell up on the new test box and somehow copy the production box bit by bit on to the test box so that they will be identical.  I am actually trying to do something similar to imaging a PC, but my copy of Ghost doesn't support FreeBSD.
Thank you for your help,
jim


Posted by w0ls0n on November 29, 2006 at 4:44:15 pm EET

Hi,

Is the hardware the same on both? If they're the same, you can use the same kernel but if they're not, I would start with a fresh kernel in m opinion.


Posted by jimd on November 29, 2006 at 4:51:44 pm EET

Yes, the hardware is exactly the same.  How would I copy the kernel to the new box before I build it?  Maybe I'm on the wrong track here.  

How would you go about building a test box that is exactly the same as an existing production box, without installing all of the software manually?  I guess what I'm really trying to avoid is installing Apache, php, samba, and nfs on the new box, I was told I could "image" the old box on the new one just by copying the data.  Is that correct?
Thanks,
jim


Posted by w0ls0n on November 29, 2006 at 5:21:28 pm EET

I am not 100% sure how you can image the box over. Thats a new one for me.

To copy the kernel just scp it like so

scp user@domain:/usr/src/sys/i386/conf/KERNELNAME /usr/src/sys/i386/conf

You might actaully have to copy it to your home dir first and then copy it to where it needs to be.


Posted by jimd on November 29, 2006 at 5:24:51 pm EET

w0ls0n,
I really appreciate your help!  Can I copy the kernel while the server is in use?


Posted by w0ls0n on November 29, 2006 at 5:49:24 pm EET

The file you're copying is file to copy over. You build it from that file.


Posted by jimd on November 29, 2006 at 10:49:19 pm EET

I just want to thank you for the excellent instructions that exist on this page.  I was able to move my kernel over from the old computer very easily thanks to you.
I really appreciate the help!
Many Thanks,
jim


Posted by w0ls0n on November 30, 2006 at 5:14:47 am EET

Anytime!


Copyright 2003 - 2010 BSD Guides.  All rights reserved.

About | Terms of Use | Privacy | Contact