APLawrence.com -  Resources for Unix and Linux Systems, Bloggers and the self-employed

Compiling FreeBSD Kernel

© December 2005 Amarjyoti Krishnan

by Amarjyoti Krishnan

Since my College days, when I was introduced to Unixes, I love to have my own compiled kernel. It gave me that special feeling of "my machine is better than yours". Besides, a custom kernel serves as an interesting conversation topic with geeks. Just ask them "What is your kernel size ?". This would keep the Geek busy for sometime where he would explain all the great things he did to the kernel to optimize his box. If you happen to be a geek yourself, this is a great question to put forward to Newbies. They'll never trouble you with stories of their nephew or kid sister after this :-D

A custom kernel boots up the system faster, it takes up lesser memory space and one can install drivers for special hardware not supported by a default kernel.

Before we get down to compiling our own kernel, it is a wonderful idea to backup the present kernel.

# cd /boot
# cp -pvr kernel kernel.orig 

The original generic kernel is now stored as kernel.orig. In case the kernel does not boot (which has happened with me many times) boot up with the generic kernel and try again. Booting any other kernel is simple. At the boot time goto to the boot prompt and simple say "boot kernel.orig" and the default kernel would boot up.

The kernel sources are located in the /usr/src/sys directory. If not installed, the kernel sources can be installed with the following commands. First insert the FreeBSD install CD in your CD drive.

 mount /cdrom
 mkdir -p /usr/src/sys
 ln -s /usr/src/sys /sys
 cat /cdrom/src/ssys.[a-d]* | tar -xzvf -

Then go to the director where the configuration files are located.

# cd /sys/i386/conf

In this directory the GENERIC kernel configuration file is located. Copy this file and it as your custom name.


First change the ident value from GENERIC to BABYBSD (or whatever name you prefer). I have given my sample configuration file at the end of this article. The options are quite easy to understand and a good starting point would be the FreeBSD Handbook which has documented most of the kernel options.

You can also go to a shell and run the command #make LINT in this directory which would create a file called LINT which has all the options supported by the kernel listed.

After this stage just run the following commands

# /usr/sbin/config BABYBSD
# cd ../compile/BABYBSD
# make depend 
# make 
# make install

Please note that you must be root to run the make install. Reboot and the kernel should boot with your shining new kernel. :-)

Please note that you must be root to run the make install. Reboot and the kernel should boot with your shining new kernel. :-)

# My Sample Kernel Configuration File for FreeBSD/i386

machine        i386

cpu                I586_CPU

cpu                I686_CPU

ident              BABYBSD

options     SCHED_4BSD        # 4BSD scheduler

options     INET            # InterNETworking

options     INET6            # IPv6 communications protocols

options     FFS            # Berkeley Fast Filesystem

options     SOFTUPDATES        # Enable FFS soft updates support

options     UFS_ACL            # Support for access control lists

options     UFS_DIRHASH        # Improve performance on big directories

options     MD_ROOT            # MD is a potential root device

options     NFSCLIENT        # Network Filesystem Client

options     NFSSERVER        # Network Filesystem Server

options     NFS_ROOT        # NFS usable as /, requires NFSCLIENT

options     MSDOSFS            # MSDOS Filesystem

options         NTFS

options     CD9660            # ISO 9660 Filesystem

options     PROCFS            # Process filesystem (requires PSEUDOFS)

options     PSEUDOFS        # Pseudo-filesystem framework

options     GEOM_GPT        # GUID Partition Tables.

options     COMPAT_43        # Compatible with BSD 4.3 [KEEP THIS!]

options     COMPAT_FREEBSD4        # Compatible with FreeBSD4

options     SCSI_DELAY=15000    # Delay (in ms) before probing SCSI

options     KTRACE            # ktrace(1) support

options     SYSVSHM            # SYSV-style shared memory

options     SYSVMSG            # SYSV-style message queues

options     SYSVSEM            # SYSV-style semaphores

options     _KPOSIX_PRIORITY_SCHEDULING # POSIX P1003_1B real-time extensions

options     KBD_INSTALL_CDEV    # install a CDEV entry in /dev

options     AHC_REG_PRETTY_PRINT    # Print register bitfields in debug

                    # output.  Adds ~128k to driver.

options     AHD_REG_PRETTY_PRINT    # Print register bitfields in debug

                    # output.  Adds ~215k to driver.

options     ADAPTIVE_GIANT        # Giant mutex is adaptive.

device        apic            # I/O APIC

# Bus support.  Do not remove isa, even if you have no isa slots

device        isa

device        eisa

device        pci

# Floppy drives

device        fdc

# ATA and ATAPI devices

device        ata

device        atadisk        # ATA disk drives

device        atapicd        # ATAPI CDROM drives

options     ATA_STATIC_ID    # Static device numbering

# SCSI peripherals

device        scbus        # SCSI bus (required for SCSI)

device        ch        # SCSI media changers

device        da        # Direct Access (disks)

device        cd        # CD

device        pass        # Passthrough device (direct SCSI access)

device        ses        # SCSI Environmental Services (and SAF-TE)

# atkbdc0 controls both the keyboard and the PS/2 mouse

device        atkbdc        # AT keyboard controller

device        atkbd        # AT keyboard

device        psm        # PS/2 mouse

device        vga        # VGA video card driver

device        splash        # Splash screen and screen saver support

# syscons is the default console driver, resembling an SCO console

device        sc

# Enable this for the pcvt (VT220 compatible) console driver

#device        vt

#options     XSERVER        # support for X server on a vt console

#options     FAT_CURSOR    # start with block cursor

device        agp        # support several AGP chipsets

# Floating point support - do not disable.

device        npx

# Power management support (see NOTES for more options)

#device        apm

# Add suspend/resume support for the i8254.

device        pmtimer

# PCI Ethernet NICs that use the common MII bus controller code.

# NOTE: Be sure to keep the 'device miibus' line in order to use these NICs!

device        miibus        # MII bus support

device        rl        # RealTek 8129/8139

# Wireless NIC cards

device        wlan        # 802.11 support

# Pseudo devices.

device        loop        # Network loopback

device        mem        # Memory and kernel memory devices

device        io        # I/O device

device        random        # Entropy device

device        ether        # Ethernet support

device        sl        # Kernel SLIP

device        ppp        # Kernel PPP

device        tun        # Packet tunnel.

device        pty        # Pseudo-ttys (telnet etc)

device        md        # Memory "disks"

device        gif        # IPv6 and IPv4 tunneling

device        faith        # IPv6-to-IPv4 relaying (translation)

# The `bpf' device enables the Berkeley Packet Filter.

# Be aware of the administrative consequences of enabling this!

# Note that 'bpf' is required for DHCP.

device        bpf        # Berkeley packet filter

# USB support

device        uhci        # UHCI PCI->USB interface

device        ohci        # OHCI PCI->USB interface

device        ehci        # EHCI PCI->USB interface (USB 2.0)

device        usb        # USB Bus (required)

#device        udbp        # USB Double Bulk Pipe devices

device        ugen        # Generic

device        uhid        # "Human Interface Devices"

device        ukbd        # Keyboard

device        umass        # Disks/Mass storage - Requires scbus and da

device        ums        # Mouse

# Specific to my Machine

device         atapicam    # for CD Writer to be detected by K3B and other CD writing software

device          sound          # To Enable Sound

device          "snd_ad1816"

device          "snd_als4000"

device          snd_cmi

device          "snd_cs4281"

device          snd_csa

device          "snd_ds1"

device          "snd_emu10k1"

device          "snd_es137x"

device          snd_ess

device          "snd_fm801"

device          snd_gusc

device          snd_ich

device          snd_maestro

device          "snd_maestro3"

device          snd_mss

device          snd_neomagic

device          "snd_sb16"

device          snd_sbc

device          snd_solo

device          "snd_t4dwave"

device          "snd_via8233"

device          "snd_via82c686"

device          snd_vibes

device          snd_uaudio

device pcii

device          acpi

device          acpi_asus

device          acpi_video

device          cbb             # cardbus (yenta) bridge

device          pccard          # PC Card (16-bit) bus

device          cardbus         # CardBus (32-bit) bus

options     DEVICE_POLLING

options     HZ=1000

options        PERFMON

device          apm_saver       # Requires APM

options         AUTO_EOI_1

options        AUTO_EOI_2

options         VESA

Amarjyoti Krishnan heads https://Bobcares.com, Tech support company for webhosts and ISPs. He is the co-founder of Poornam Info Vision Ltd., a software and IT services company which specializes in Linux based solutions for Webhosts and ISPs. Poornam Info Vision is an ISO 9001:2000 certified company with a team of over 100 engineers.

Amarjyoti is a Computer Engineer based in India and has over 7 years of experience in the hosting industry. He has spoken and written extensively on the subject. His articles have been published both online as well as in print in magazines.

Got something to add? Send me email.

(OLDER)    <- More Stuff -> (NEWER)    (NEWEST)   

Printer Friendly Version

-> Compiling FreeBSD Kernel

Inexpensive and informative Apple related e-books:

Are Your Bits Flipped?

Take Control of Numbers

Take Control of iCloud, Fifth Edition

Take Control of the Mac Command Line with Terminal, Second Edition

Take Control of iCloud

More Articles by © Amarjyoti Krishnan

Printer Friendly Version

Have you tried Searching this site?

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more.

Contact us

Printer Friendly Version

People who are more than casually interested in computers should have at least some idea of what the underlying hardware is like. Otherwise the programs they write will be pretty weird. (Donald Knuth)

Linux posts

Troubleshooting posts

This post tagged:


Unix/Linux Consultants

Skills Tests

Unix/Linux Book Reviews

My Unix/Linux Troubleshooting Book

This site runs on Linode