Compile and install Linux kernel steps

Source: Internet
Author: User

To compile and install the Linux kernel steps:

I. Obtaining the kernel source code

Source URL: www.kernel.org

Two. Unzip the kernel source

First log in as root and enter the/USR/SRC subdirectory. If the user installs the kernel's source code while installing Linux, a linux-x.y.z subdirectory is found. The source code for the kernel x.y.z is stored in this directory. In addition, you will find a link to the directory Linux. Delete the connection, and then copy the source files of the new kernel to the/USR/SRC directory and unzip:
# tar ZXVF linux-2.3.14.tar.gz

After the file is released successfully, a Linux subdirectory is generated in the/USR/SRC directory.  It contains all the source code of the kernel 2.3.14. Link/usr/include/asm,/usr/inlude/linux,/USR/INCLUDE/SCSI to the corresponding directory in the/usr/src/linux/include directory.

# Cd/usr/include
# RM-RF ASM Linux
# ln-s/usr/src/linux/include/asm-i386 ASM
# ln-s/usr/src/linux/include/linux Linux
# ln-s/USR/SRC/LINUX/INCLUDE/SCSI SCSI

Delete the remaining. o files and other subordinate files in the source code directory.
# Cd/usr/src/linux
# Make Mrproper

Three. Incremental patches

Sometimes do not need to completely reinstall, just hit the incremental patch, similar to upgrade, run in the kernel source root directory:

patch-p1<. /patch-x.y.z

Four. Kernel Source tree directory:
Arch:Contains code related to hardware architecture, each of which occupies a corresponding directory. and 32-bit PC-related code is stored in the I386 directory, where the more important include kernel (kernel core), mm (memory management), MATH-EMU (floating-point unit emulation), LIB (Hardware-related tool function), boot (boot program), PCI (PCI bus) and power (CPU-related status).
BLOCK:Part of the block device driver.
Crypto:Commonly used encryption and hashing algorithms (such as AES, SHA, etc.), there are some compression and CRC check algorithms.
Documentation:General explanations and comments about the parts of the kernel.
drivers:A device driver that consumes a subdirectory for each different driver.
FS:Various supported file systems, such as EXT, FAT, NTFS, and so on.
include:Header file. Among them, the system-related header files are placed under the Linux sub-directory.
Init:Kernel initialization code (note that it is not the system boot code).
IPC:The code for inter-process communication.
Kernel:The core components of the kernel, including process scheduling, timers, etc., are part of the platform-related code in the Arch/*/kernel directory.
Lib:Library file code.
mm:Memory management code, and part of the platform-related code is placed in the ARCH/*/MM directory.
Net:Network-related code, the implementation of a variety of common network protocols.
Scripts:The script file used to configure the kernel files.
Security:is primarily a selinux module.
Sound :Drivers for commonly used audio devices.
usr:Implements a cpio.
Under the i386 system, the system boot will be executed starting from Arch/i386/kernel/head.s, and then transferred to the main () function in init/main.c to initialize the kernel.

Five. Configuring the kernel

# Cd/usr/src/linux

There are three ways to configure the kernel:

(1) command line: Make Config
(2) Menu mode Configuration interface: Make Menuconfig

(3) X Window:make xconfig

The kernel configuration program for Linux provides a range of configuration options. For each configuration option, the user can answer "y", "M", or "n". where "Y" means the support or device driver of the corresponding feature is compiled into the kernel; "M" means that the support or device driver for the corresponding feature is compiled into a loadable module, which can be added to the kernel by the system or user, if required, and "n" means that the kernel does not provide support for the corresponding feature or driver. Because of the many configuration options in the kernel, this article only describes some of the more important options.

1. Code Maturity Level Options (coding maturity option)
Prompt for development and/or incomplete code/drivers (config_experimental) [n/y/?] If the user wants to use code or drivers that are still in the test phase, you can select Y. If you want to compile a stable kernel, select "N".
2. Processor type and features (processor type and features)
(1), Processor family (386, 486/cx486, 586/k5/5x86/6x86, PENTIUM/K6/TSC, PPRO/6X86MX) [PPRO/6X86MX] Select processor type, default = ppro/ 6x86mx.
(2), Maximum physical memory (1GB, 2GB) [1GB] The maximum number of memories supported by the kernel, the default is 1G.
(3), Math emulation (config_math_emulation) [n/y/?] coprocessor emulation, default is no emulation.
(4), MTRR (Memory Type Range Register) Support (CONFIG_MTRR) [n/y/?]
Select this option and the system will generate a/PROC/MTRR file to manage MTRR for use by x server.
(5), symmetric multi-processing Support (CONFIG_SMP) [y/n/?] Select "Y" and the kernel supports symmetric multiprocessor.
3. Loadable module support (can be loaded with modules)
(1), Enable loadable module Support (config_modules) [y/n/?] Select "Y" and the kernel supports loading modules.
(2), Kernel module loader (config_kmod) [n/y/?] Select "Y", the kernel will automatically load those loadable modules, otherwise users need to manually load.
4. General Setup (normal Setup)
(1), Networking Support (config_net) [y/n/?] This option sets whether the network supports are available in the kernel.
(2), PCI support (CONFIG_PCI) [y/n/?] This option sets whether PCI supports are available in the kernel.
(3), PCI access mode (BIOS, Direct, any) [any] This option sets the way Linux probes PCI devices. Select "BIOS", Linux will use the BIOS, select "Direct", Linux will not pass the BIOS, select "Any", Linux will directly detect the PCI device, if it fails, then use the BIOS.
(4) Parallel Port Support (config_parport) [n/y/m/?] Select "Y" and the kernel supports parallel ports.
5. Plug and Play configuration (Plug and Play device support)
(1), Plug and Play Support (CONFIG_PNP) [y/m/n/?] Select "Y" and the kernel will automatically configure the Plug and Play device.
(2), ISA Plug and Play Support (CONFIG_ISAPNP) [y/m/n/?] Select "Y" and the kernel will automatically configure the ISA bus-based Plug and Play device.
6, block devices (blocks equipment)
(1), Normal PC floppy disk support (CONFIG_BLK_DEV_FD) [y/m/n/?] Select "Y", and the kernel will provide the floppy.
(2), Enhanced Ide/mfm/rll disk/cdrom/tape/floppy Support (config_blk_dev_ide) [y/m/n/?] Select "Y", the kernel will provide the enhanced IDE hard disk, Support for CDROM and tape drives.
7. Networking Options (Network option)
(1), Packet socket (config_packet) [y/m/n/?] Select Y, and some applications will use the Packet protocol to communicate directly with the network device without passing through the other mediation protocols in the kernel.
(2), Network firewalls (config_firewall) [n/y/?] Select "Y" and the kernel will support the firewall.
(3), TCP/IP networking (config_inet) [y/n/?] Select "Y" and the kernel will support the TCP/IP protocol.
(4) The IPX protocol (CONFIG_IPX) [n/y/m/?] Select "Y" and the kernel will support the IPX protocol.
(5), Appletalk DDP (config_atalk) [n/y/m/?] Select "Y" and the kernel will support the Appletalk DDP protocol.
8. SCSI support (SCSI supported)
If the user wants to use a SCSI device, you can configure the appropriate option.
9. Network Device Support
Network device Support (config_netdevices) [y/n/?] Select "Y", and the kernel will provide supported networking drivers.
10, Ethernet (100Mbit) (10M or 100M Ethernet)
In this setting, the system provides a number of network card drivers, the user can only choose their own network card driver. In addition, users can add support for FDDI, PPP, slip, and Wireless LAN (Wireless LAN) to the kernel as needed.
11. Character devices (character device)
(1), virtual terminal (CONFIG_VT) [y/n/?] Select "Y" and the kernel will support the virtual terminal.
(2), support-Console on virtual terminal (config_vt_console) [y/n/?]
Select "Y" and the kernel can use a virtual terminal as the system console.
(3), standard/generic (dumb) serial Support (config_serial) [y/m/n/?]
Select "Y" and the kernel will support the serial port.
(4), support-Console on serial port (config_serial_console) [n/y/?]
Select "Y" and the kernel can use a serial port as the system console.
12. Mice (mouse)
PS/2 Mouse (aka "Auxiliary Device") support (Config_psmouse) [y/n/?] If the user is using a PS/2 mouse, this option should select "Y".
13. filesystems (File system)
(1), Quota Support (Config_quota) [n/y/?] Select "Y" and the kernel supports disk quotas.
(2), Kernel automounter Support (CONFIG_AUTOFS_FS) [y/m/n/?] Select "Y", the kernel will provide the Automounter to enable the system to automatically mount the remote file system at startup.
(3), DOS Fat FS Support (CONFIG_FAT_FS) [n/y/m/?] Select "Y", and the kernel supports the DOS FAT file system.
(4), ISO 9660 CDROM filesystem Support (CONFIG_ISO9660_FS) [y/m/n/?]
Select "Y" and the kernel will support the ISO 9660 CDROM file system.
(5), NTFS filesystem support (read only) (CONFIG_NTFS_FS) [n/y/m/?]
Select Y to enable the user to access the NTFS file system as read-only.
(6),/proc filesystem Support (CONFIG_PROC_FS) [y/n/?]/proc is a virtual file system that stores the running state of a Linux system, which must select "Y".
(7), Second extended FS Support (CONFIG_EXT2_FS) [y/m/n/?] EXT2 is a standard file system for Linux, which must also select "Y".
14. Network File Systems
(1), NFS filesystem Support (CONFIG_NFS_FS) [y/m/n/?] Select "Y" and the kernel supports NFS file system.
(2), SMB filesystem support (to mount WfW shares etc) (CONFIG_SMB_FS)
Select "Y" and the kernel will support the SMB file system.
(3), NCP filesystem support (to Mount NetWare volumes) (CONFIG_NCP_FS)
Select "Y" and the kernel will support the NCP file system.
15, Partition Types (partition type)
This option supports some less commonly used partition types, and if necessary, select "Y" on the appropriate option.
16. Console drivers (console driver)
VGA text Console (config_vga_console) [y/n/?] Select "Y" and the user can use Linux in the standard VGA display mode.
17. Sound (voice)
Sound card support (config_sound) [n/y/m/?] Selects "Y", and the kernel can provide the audio card.
18, Kernel hacking (kernel monitoring)
Magic sysrq Key (CONFIG_MAGIC_SYSRQ) [n/y/?] Select "Y" to allow the user to partially control the system. In general, select "N".

Six, compile the kernel
(i), build the required subordinate files at compile time
# Cd/usr/src/linux
# make DEP
(ii), clear the kernel compiled target file
# Make Clean
(c), compile the kernel
# Make Zimage
After the kernel compiles successfully, a new kernel image file Zimage is generated in the/usr/src/linux/arch/i386/boot directory. If the compiled kernel is large, you will be prompted to compile using the Make Bzimage command. At this point, the compiler generates a kernel image file called Bzimage.
(iv), compile loadable modules
If the user sets loadable modules when configuring the kernel, these modules need to be compiled for future loading with the Insmod command.
# Make Modules
# Make Modelus_install
After the compilation is successful, a 2.3.14 subdirectory is generated in the/lib/modules directory with all the loadable modules of the new kernel.
Seven, start the new kernel
(i), copy the new kernel and System.map files to the/boot directory
# cp/usr/src/linux/arch/i386/boot/bzimage/boot/vmlinuz-2.3.14
# cp/usr/src/linux/system.map/boot/system.map-2.3.14
# Cd/boot
# rm-f System.map
# ln-s system.map-2.3.14 System.map
(b), configure the/etc/lilo.conf file. Add the following lines to the file:
default=linux-2.3.14
image=/boot/vmlinuz-2.3.14
label=linux-2.3.14
Root=/dev/hda1
Read-only
(iii) to make the new configuration effective
#/sbin/lilo
(iv), restart the system
#/sbin/reboot
If the new kernel does not start properly, the user can start the old kernel at the Lilo: prompt. Then find out the cause of the failure, recompile the new kernel.

Compile and install Linux kernel steps

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.