Compiling a FreeBSD Kernel
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 😀
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.
In this directory the GENERIC kernel configuration file is located. Copy this file and it as your custom name.
#cp -pvr GENERIC BABYBSD # vi BABYBSD
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
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
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 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
# Floppy drives
# ATA and ATAPI devices
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
# Enable this for the pcvt (VT220 compatible) console driver
#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.
# Power management support (see NOTES for more options)
# Add suspend/resume support for the i8254.
# 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 cbb # cardbus (yenta) bridge
device pccard # PC Card (16-bit) bus
device cardbus # CardBus (32-bit) bus
device apm_saver # Requires APM
About the author:
Amarjyoti Krishnan heads http://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.
Personal blog site: amarjyoti.com