FreeBSD kernel Compilation

Source: Internet
Author: User
Tags passthrough
I used to hear about how to compile the kernel, and I felt very excited. Haha, especially for free-developed operating systems like FreeBSD, it is very good. I can customize the kernel by myself. I just want to know how to get it, it can increase the speed and ensure security and stability, so I will try to customize the kernel. (I am also a newbie. If an error occurs in this article, please correct me !)
The FreeBSD version I used is 5.2.1 and is now relatively new. I will check my Kernel File Size:
# Ls-L/boot/kernel
-R-XR-x 1 root wheel 5940286 Feb 24 2004/boot/kernel. bak/kernel
It seems not too small, more than 5 MB, huh, I want to make it around 3 MB, huh, begin...
1. Install the kernel source code
To compile the kernel, we must first ensure that the source code of the kernel is in. Let's see if our system has been installed:
# Ls/usr/src/sys
Ls:/usr/src/sys: no such file or directory
It proves that we have not installed the kernel source code. Well, we will install it. The kernel source code is installed in the/usr/src/sys directory by default. If this directory does not exist, it indicates that you do not
Installation source code is available.
We first put our FreeBSD installation CD into the optical drive, then execute/STAND/sysinstall as root under FreeBSD, select configure, and then
Distributions, SRC, sys, and press enter to start installation. Generally, the installation can be completed in just a few minutes. After installation, you can view the folder:
# Ls/usr/src/sys
Makefile DDB libkern netkey PCI
Alpha Dev modules netnatm posix4
Amd64 FS net netncp powerpc
Arm Geom net80211 netsmb RPC
Boot GNU netatalk NFS security
Cam i386 netatm nfs4client sparc64
Coda i4b netgraph nfsclient sys
Compat IA64 netinet nfsserver tools
Conf ISA netinet6 opencrypto UFS
Contrib isofs netipsec pc98 VM
Crypto Kern netipx pccard
After the source code is installed, we can start configuring the kernel.
Ii. Configure the Kernel File
In fact, the key to compiling the kernel is to configure the kernel file. The directory of the Kernel configuration file is under/usr/src/sys/i386/CONF. Let's go to the directory to change it:
# Cd/usr/src/sys/i386/Conf
# Ls
Generic generic. Hints notes PAE
Makefile oldcard gethints. awk
The Kernel configuration file is generic. We need to configure it, including the hardware support, IPv6 support, and nic. To prevent problems in the configuration file,
Let's back up it first:
# Cp generic. Bak
Then we can use any editor to open the file, which can be opened by VI or EE. For convenience, I will use EE to open the file:
# Ee generic
After opening, there are similar:
# Generic -- generic Kernel configuration file for FreeBSD/i386
#
# For more information on this file, please read the Handbook section on
# Kernel configuration files:
"#" Indicates that the content or option is annotated. If we want to remove any option, we can add "#", you can also delete the options you do not need,
I recommend that you add "#" in front of unnecessary options "#".
For details about how to modify the configuration file, refer to the FreeBSD Chinese manual about Kernel configuration options:
Http://www.freebsd.org.cn/snap/doc/zh_CN.GB2312/books/handbook/kernelconfig-config.HTML
My configuration file is modified in this way. I will not describe it in detail. Please refer to the configuration file above. It should be suitable for most machines without Isa, SCSI, raid and other devices.
Generic Kernel configuration file Configuration:
######################################## ######################################## #########
#
# Generic -- generic Kernel configuration file for FreeBSD/i386
#
# For more information on this file, please read the Handbook section on
# Kernel configuration files:
#
# Http://www.FreeBSD.org/doc/en_US.ISO8859-1/books/handbook/kernelconfig-config.html
#
# The handbook is also available locally in/usr/share/doc/handbook
# If youve installed the doc distribution, otherwise always see
# FreeBSD World Wide Web Server (http://www.FreeBSD.org/) for
# Latest information.
#
# An exhaustive list of options and more detailed explanations of
# Device lines is also present in the.../../CONF/notes and notes files.
# If you are in doubt as to the purpose or necessity of a line, check first
# In notes.
#
# $ FreeBSD: src/sys/i386/CONF/generic, V 1.394.2.3 2004/01/26 19:42:11 nectar exp $
Machine i386
# CPU i486_cpu
# CPU i586_cpu
CPU i686_cpu
Ident generic
# To statically compile in device wiring instead of/boot/device. Hints
# Hints "Generic. Hints" # default places to look for devices.
# Makeoptions DEBUG =-G # Build kernel with GDB (1) debug symbols
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 pseudo DOFs)
Options pseudo DOFs # pseudo-filesystem framework
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 ~ 128 K to driver.
Options ahd_reg_pretty_print # print register bitfields in debug
# Output. Adds ~ 215 K to driver.
Options pfil_hooks # pfil (9) Framework
# Debugging for use in-Current
# Options DDB # enable the kernel debugger
# Options invariants # enable callof extra sanity checking
# Options invariant_support # extra sanity checks of internal structures, required by Invariants
# Options witness # enable checks to detect deadlocks and cycles
# Options witness_skipspin # dont run witness on spinlocks for speed
# To make an SMP kernel, the next two are needed
# Options SMP # invalid Ric multiprocessor Kernel
# Device APIC # I/O APIC
Device Isa
Device Eisa
Device PCI
# Floppy drives
Device FDC
# ATA and atapi Devices
Device ATA
Device atadisk # ata disk drives
# Device ataraid # ata raid drives
Device atapicd # atapi CDROM drives
Device atapifd # atapi floppy drives
# Device atapist # atapi tape drives
Options ata_static_id # static device numbering
# SCSI controllers
# Device AHB # EISA aha1742 family
# Device AHC # aha2940 and onboard aic7xxx Devices
# Device ahd # aha39320/29320 and onboard aic79xx Devices
# Device amd # amd 53c974 (tekram DC-390 (t ))
# Device ISP # Qlogic family
# Device MPT # LSI-logic MPT-Fusion
# Device NCR # NCR/symbios Logic
# Device sym # NCR/symbios logic (newer chipsets + those of 'NCR)
# Device TRM # tekram dc395u/UW/F dc315u adapters
# Device adv # advansys SCSI adapters
# Device adw # advansys wide SCSI adapters
# Device aha # adaptec 154x SCSI adapters
# Device AIC # adaptec 15 [012] x SCSI adapters, AIC-6 [23] 60.
# Device BT # buslogic/mylex multimaster SCSI adapters
# Device NCV # NCR 53c500
# Device NSP # workbit ninja SCSI-3
# Device STG # TMC 18c30/18c50
# SCSI peripherals
Device scbus # SCSI bus (required for SCSI)
# Device ch # SCSI media changers
# Device da # direct access (disks)
# Device SA # sequential access (Tape etc)
# Device CD # cd
# Device pass # passthrough device (direct SCSI access)
# Device ses # SCSI environmental services (and SAF-TE)
# Raid controllers interfaced to the SCSI subsystem
# Device AMR # AMI megaraid
# Device ASR # DPT smartraid V, VI and adaptec SCSI raid
# Device CISS # Compaq smart RAID 5 *
# Device DPT # DPT smartcache III, IV-See Notes for options
# Device IIR # intel integrated raid
# Device IPS # IBM (adaptec) serveraid
# Device mly # mylex acceleraid/extremeraid
# Raid Controllers
# Device AAC # adaptec FSA raid
# Device aacp # SCSI passthrough for aac (requires cam)
# Device Ida # Compaq smart raid
# Device mlx # mylex dac960 family
# Device PST # Promise supertrak sx6000
# Device twe #3 ware ata raid
# 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
# Pccard (PCMCIA) Support
# PCMCIA and carrentbridge support
# Device CBB # carstrap (yenta) Bridge
# Device pcic # exca ISA and PCI Bridges
# Device pccard # PC Card (16-bit) Bus
# Device carw.# carw.( 32-bit) Bus
# Serial (COM) Ports
# Device sio# 8250, 16 [45] 50 based serial ports
# Parallel port
Device PPC
Device ppbus # Parallel Port bus (required)
# Device LPT # printer
Device PLIP # TCP/IP over parallel
Device PPI # parallel port interface device
# Device VPO # requires scbus and DA
# If youve got a "dumb" serial or parallel PCI card that is
# Supported by the PUC (4) glue driver, uncomment the following
# Line to enable it (connects to the SIO and/or PPC drivers ):
# Device PUC
# PCI Ethernet protocol.
# Device de # DEC/Intel dc21x4x (''tulip)
Device em # Intel PRO/1000 adapter Gigabit Ethernet Card
# Device txp # 3Com 3cr990 (''typhoon)
# Device VX # 3Com 3c590, 3c595 (''vortex)
# PCI Ethernet protocol that use the common MII bus controller code.
# Note: Be sure to keep the device miibus line in order to use these messages!
Device miibus # MII bus support
# Device bfe # Broadcom bcm440x 10/100 Ethernet
# Device Bge # Broadcom bcm570xx Gigabit Ethernet
# Device DC # DEC/Intel 21143 and various workalikes
Device fxp # intel etherexpress Pro/100b (82557,825 58)
# Device PCN # amd am79c97x PCI 10/100 (precedence over lnc)
# Device re # RealTek 8139c ++/8169/8169 S/8110 s
# Device RL # realtech 8129/8139
# Device SF # adaptec AIC-6915 (''Starfire)
# Device SIS # Silicon Integrated Systems SIS 900/SIS 7016
# Device SK # syskonnect SK-984x and SK-982x Gigabit Ethernet
# Device ste # Sundance st201 (D-link DFE-550TX)
# Device ti # Alteon networks tigon I/II Gigabit Ethernet
# Device TL # Texas Instruments thunderlan
# Device TX # SMC etherpower II (83c170 ''epic)
# Device VR # via Rhine, Rhine II
# Device WB # WINBOND w89c840f
# Device XL # 3Com 3c90x (''boomerang, ''cyclone)
# ISA Ethernet certificate. pccard has been added.
# Device Cs # crystal semiconducs89x0 Nic
# Device ED requires device miibus
# Device ED # ne [12] 000, SMC Ultra, 3c503, ds8390 cards
# Device ex # intel etherexpress Pro/10 and Pro/10 +
# Device EP # etherlink III based cards
# Device Fe # Fujitsu mb8696x based cards
# Device ie # etherexpress 8/16, 3c507, starlan 10 etc.
# Device lnc # ne2100, NE32-VL Lance Ethernet cards
# Device Sn # SMCs 9000 Series of Ethernet chips
# Device Xe # xircom pccard Ethernet
# ISA devices that use the old ISA shims
# Device le
# Wireless Nic cards
# Device WLAN #802.11 support
# Device an # Aironet 4500/4800 802.11 Wireless routing.
# Device AWI # baystack 660 and others
# Device wi # wavelan/intersil/Symbol 802.11 Wireless cable.
# Device WL # older non 802.11 wavelan wireless Nic.
# Pseudo devices-the number indicates how many units to allocate.
Device random # entropy Device
Device loop # network loopback
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!
Device BPF # Berkeley Packet Filter
# USB support
Device uhci # uhci PCI-> USB Interface
Device OHCI # ohci pci-> USB Interface
Device USB # USB Bus (required)
# Device udbp # USB double bulk pipe Devices
Device ugen # Generic
Device uhid # "Human Interface Devices"
Device ukbd # keyboard
# Device ulpt # printer
Device UMass # disks/Mass Storage-requires scbus and DA
Device ums # mouse
Device urio # Diamond Rio 500 MP3 player
# Device uers # Scanners
# USB Ethernet, requires MII
Device aue # admtek USB Ethernet
Device axe # asix electronics USB Ethernet
Device cue # catc USB Ethernet
Device Kue # Kawasaki lsi usb Ethernet
# FireWire support
# Device FireWire # FireWire bus code
# Device systolic # SCSI over FireWire (requires scbus and DA)
# Device fwe # Ethernet Over FireWire (non-standard !)
#
######################################## ######################################## ##############
After the configuration is complete, Press ESC, and then prompt to press "a" and then press "a" to save the configuration file.
3. Compile the kernel:
After the Kernel File is configured, the kernel can be compiled. There are generally two compilation methods. We adopt the traditional compilation method.
Go to the/usr/src/sys/i386/conf directory:
# Cd/usr/src/sys/i386/Conf
Run the config command to generate the kernel source code.
#/Usr/sbin/config generic
Switch to the directory where the kernel is created.
# CD ../compile/generic
Compile the kernel
# Make depend
# Make
Install the new kernel.
# Make install
OK. Here, if there is no error in the middle, our core has been installed successfully, and reboot will be able to use our new compiled kernel. If
Errors. Check whether your steps are consistent with the preceding steps. Also, check whether the configuration of your Kernel configuration file is correct. If the compilation fails, the kernel file configuration is incorrect.
, Please check carefully.
4. The new kernel cannot be started:
If the compiled kernel cannot be started, you can use the previous kernel to start it. After a kernel is compiled, the old kernel is backed up. Generally,/boot/kernel. Old is the old kernel.
If there is a problem with the core backup, the kernel can be started for a long time.
The specific implementation method is as follows:
You can press any key other than enter when the system starts to count 10, then type the unload command, then type boot kernel. Old, or any kernel name that can be started normally.
Then, the system can be started normally, and then the Kernel configuration will be re-performed after the system enters.
Note: You cannot rely solely on kernel. Old because when you install a new kernel, kernel. Old will be overwritten by the kernel installed last time, so you can manually back up one
The kernel to be started normally, or check whether your kernel. Old kernel can be started normally.
End
Well, here we have finished compiling the kernel. Let's see if our kernel has been reduced:
# Ls-L/boot/kernel
-R-XR-x 1 root wheel 3090929 Sep 1/boot/kernel
Haha, it is obvious that the original 5940286 has changed to the current 3090929, although it has not become twice smaller, but it has also become much smaller, and the system will be faster in the future!
Note: This document is performed in freebsd5.2.1 and may not be applicable to other versions, especially freebsd4.x. If any problem occurs, see the manual.
Appendix:
FreeBSD Chinese manual: http://www.freebsd.org.cn/snap/doc/zh_CN.GB2312/books/handbook/index.html
Core configuration reference: http://www.freebsd.org.cn/snap/doc/zh_CN.GB2312/bos/handbook/kernelconfig.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.