Home PC Games Linux Windows Database Network Programming Server Mobile  
  Home \ Linux \ Introduces Linux kernel compilation system and compiler installation     - shell script: MySQL startup script simple (Database)

- MySQL remote connection settings (Database)

- Oracle SQL statement to retrieve data paging table (Database)

- How to Upgrade Ubuntu GNOME 14.10 to GNOME 3.16 Desktop (Linux)

- Make full use of the Raspberry Pi SD card space (Linux)

- To install the mail client terminal Evolution 3.13.2 under Ubuntu 14.04 (Linux)

- Linux environment installation of rvm and ruby (Linux)

- Detailed driver compiled into the Linux kernel (Programming)

- A simple shell script for monitoring in Linux (Linux)

- Understand ASP.NET 5 running the command: DNVM, DNX, and DNU (Server)

- RedHat Linux source code package installation process (Linux)

- Use Android Studio and Gradle packaged multi-version APK (Programming)

- Oracle user lock how to know what causes (Database)

- To compile and install MySQL 5.7.7 RC under CentOS 7.1 (Database)

- JEdit 5.2 Pro Edition installation on Ubuntu 14.04 (Linux)

- Linux system components Detailed log (Linux)

- Ubuntu and Archlinux install Notepadqq 0.50.2 (Linux)

- MongoDB study notes - polymerization (Database)

- Ubuntu users how to install the latest Nvidia graphics drivers (Linux)

- The ActiveMQ JMS installation and application examples for Linux (Linux)

  Introduces Linux kernel compilation system and compiler installation
  Add Date : 2018-11-21      
  Here is not just talk how to build, install the Linux kernel, but the main thing is to introduce the kernel build system and all important documents. Finally, the use of learned compile and install the Linux kernel to modify Linux 01 is scheduled to become stochastic scheduling. If you just need to compile and install the kernel a few instructions, then turn to the article after part of it. If there are not too clear where or wrong, please correct me. Thank you for reading!

Kernel Well, that is the core of Linux, if you use Linux just to listen to songs, watch movies, on the Internet, then I think Linux is not for you. But it can open this article is to Linux then you should have interested. Here we compiled with this IT world's most perfect work of art! ---- Linux kernel

Let's look at the source code before compiling the directory structure of the Linux kernel. It helps to understand the Linux kernel, familiar with her, and there will be no feeling of fear and helplessness.

CONTENTS kernel source structure:

1) Documentation There is no code, there are only some of a wide variety of documents, but it can give us more than enough help.

2) arch architecture all related source code here, as well as in include / asm - * / directory. Supported architectures in the arch directory corresponding subdirectories, and contain a minimum of three subdirectories.

kernel: support the realization of signal processing, SMP and other architecture-specific.

lib: to strlen, achieve universal function memcpy like architecture-specific.

mm: Obviously it, this is architecture-related memory management implementation.

Most subdirectory contains boot this subdirectory, start some or all of the code used by the kernel on the hardware platform.

3) drivers here are the graphics, scsi adapter pic bus, usb bus and other linux supported peripherals and bus drivers. Kernel is one of the largest directories.

4) fs file system. There VFS, various file system code here.

5) include a core containing most of the header files.

6) inter-process communication ipc, including semaphores, shared memory, and other forms of ipc code.

7) kernel includes the scheduling process, create, revoke another part of the core code and the platform-dependent. It is the core part of the kernel.

8) init kernel initialization part of the code. Including main.c and created an early code for the user space and the like.

9) lib library code

10) mm and the architecture-independent memory management code.

11) net realized networking code, common protocols such as TCP / IP, IPX.

12) scripts there is no code, only some kernel to configure the script file. When we compile the kernel, run make menuconfig command such as we are with the script directory in this interaction.

13) implement block block layer.

14) security linux security model code.

15) crypto. Kernel itself encryption API, to achieve a common encryption algorithms and hashing algorithms, and some of the compression, CRC checksum algorithm.

16) sound card drivers and other sound-related code.

17) usr for packaged and compressed cpio like.

Here, when you open the linux source code you will no longer feel so helpless. Let's continue.

Here are a few important documents.

1) vmlinuz kernel boot file

vmlinuz is a bootable compressed kernel, "vm" on behalf of "Virtual Memory". Linux can use hard disk space as virtual memory, hence the name "vm". vmlinuz not executable Linux kernel (the Internet that is the kernel that can be performed, may be incorrect. Because it is compressed, to be performed must be unpacked. Hope Great God enlighten!), and therefore the most important task in the startup stage is the self-extracting kernel image, it located in / boot / vmlinuz, it is generally a soft link. zImage (vmlinuz, small kernel less than 512kb) and bzImage (vmlinuz, large kernels greater than 512kb) are compressed with gzip. Not only are they a compressed file, but embedded in the beginning of these two files are gzip decompression code. So you can not use gunzip or gzip -dc to unpack vmlinuz. Kernel file contains a miniature gzip to decompress the kernel and boot it. The difference between the two is that the old zImage decompression to low kernel memory (the first 640K), bzImage decompression kernel into high memory (1M or more). If the kernel is small, you can use one of zImage or bzImage, the same two ways to boot the system is running. Big kernel using bzImage, can not be used zImage.

2) vmlinux

vmlinuz is a compressed version of vmlinux.

3) initrd.img

initrd.img, namely "initrd RAM disk", is a small image that contains a minimal linux system. The usual first step is to start the kernel after kernel to vmlinuz file extraction but before the real root file system startup, initrd.img file is loaded into memory. Kernel mounts initrd.img, and execute the script to further mounted inside a variety of modules, then find the real root partition, mount and execute / sbin / init. If not initrd.img, then the kernel will try to directly mount the root partition.

linux root file system can be stored on a lot of media, such as SCSI, IDE, USB, etc. If these drivers are compiled into the kernel, the kernel will become very bloated, huge ah! So the linux kernel to retain only the most basic startup code, and the support of various hardware devices in the form of modules placed in initrd.img. The advantage is that you can start the process of loading the required modules from initrd to mount the root file system, which can kernnel under the same circumstances, modify the initrd to achieve the flexibility to support different hardware. In the final stage of completion of startup, the root file system is remounted to another device up.

For example, your hard drive is a SCSI interface, but your kernel does not support this kind of interface, your kernel is no way to access the hard disk, you can not load the file system on the hard drive, how to do this? ? initrd.img is a ram disk image file. ram disk is a part of the memory occupied by the analog to disk, so that our operating system access. ram disk is a standard kernel file awareness device (/ dev / ram0) file system is also standard kernel recognized file system. Kernel load this ram disk as the root file system and begin to implement one of these files --init (2.6 kernel is more than init file, located in / sbin /) to load various modules, and service. After some configuration and running, you can go to a physical disk to load the real root partition, and then some configuration, and finally the successful launch.

So initrd.img is the role of some of the drivers and command tools packed into img in simplifying the kernel, which is fully in line with the design philosophy linux and linux, ah!

4) system.map, the kernel symbol table, located /boot/System.map. When you compile a new kernel, the kernel's address of each symbol will change, for the old kernel symbol table for the new kernel is wrong, if you also use the old kernel symbol table will be wrong, so It will generate a new kernel symbol table that is system.map

Here is another file or directory is very important.

/ Lib / modules / compilation including their own, and the system comes with the kernel modules, and other files

/ Lib / modules / < kernel-version > / build / compile the file storage needs of the new module. There Makefile, .config, modules.symVers and kernel headers.

/ Lib / modules / < kernel-version > / kernel / file storage module ko

Alias definitions /lib/modules/< kernel-version >/modules.alias module, module loading tools use it to load the appropriate module.

/lib/modules/< kernel-version >/modules.dep defines the inter-module dependency relationship.

/lib/modules/< kernel-version >/modules.symbols marked with the symbol belongs to which module.

Configure the system and mechanism of the kernel: consists of three files to control, it is a Makefile, is a .config, one kconfig. Makefile located in the root CONTENTS layers and subdirectories kernel source code, the provisions of the kernel is how compilation. .config Configuration file is generated after configuration file, record the result of the configuration. The kconfig configuration interface is generated to use the file. When configuring read options here.

make menuconfig procedure:

1) mentioned earlier scripts, remember? It is used to store and make menuconfig interface related drawing file.

2) When we execute make menuconfig will be in arch / $ (ARCH) / directory read kconfig files generated interface configuration options. ARCH and what is it? It consists of Makefile files in the root directory of the decision. Makefile has this environment variable definition

3) kconfig generate for our optional configuration options, but inevitably some people will not set, so the arch / $ (ARCH) / configs folder under the default configuration file ready for us, there are many options, the system will choose that it? In fact, the kernel will read the default root directory .config file as the default option.

4) .config for different kernel options we choose will be different. We choose the configuration interface via the spacebar to select an option or not, in the end when you exit our configuration will be recorded in the .config inside. Here we have completed the configuration process. But we configure how Contact compiler together? Do not worry, we continue!

5) configuration is saved in .config in the same time the system will be all the options as macros stored in include / generated / autoconf.h file. It will be based on these macros to compile time.

Here the basic mechanism to compile finished. The following look back vmlinux file. . . . .

Vmlinux framework: the front vmlinux importance already talked about. linux kernel build system is very complex, and can simply look at vmlinux here is how come. As shown, the first kernel compilation box set up in the top five, which is divided into many small form five formation, and ultimately will be linked to the formation of these five vmlinux. For kallsyms.o which records the address of non-core stack variables, including the variables and functions, but it relates to the last link to get vmlinux.

Compilation process kallsyms.o module (! See online article, learn to write here write here is relatively simple):

1) First, the compiler will most of the core components of a link to a file .tmp_vmlinux1.

2) command nm will .tmp_vmlinux1 symbols and corresponding address lead out and use the tool to generate tmp_kallsyms1.S kallsyms files.

3) .tmp_kallsyms1.S compile files generated .tmp_kallsyms1.o

4) Repeat 1) link process, 3) obtained .tmp_kallsyms1.o link into the kernel, get .tmp_vmlinux2 file.

5) and almost 2, the command nm will .tmp_vmlinux2 symbols and corresponding address lead out and use the tool to generate tmp_kallsyms2.S kallsyms files.

6) .tmp_kallsyms2.S compile files generated .tmp_kallsyms2.o

7) The .tmp_kallsyms2.o as kallsyms module is linked into the kernel formed vmlinux.

The following hands-compile the kernel! Experiment came. . . . . .

Compile the kernel experiment:

Listed first and password to install software required for it. First kernel.org specifically address the need to install the kernel https://www.kernel.org/pub/linux/kernel/v2.6/ download, extract the main folder. In 2.6.24 it. Open Terminal (Ubuntu shortcuts are: ctrl + Alt + t).


1) cd linux-2.6.24 into the directory

2) make menconfig kernel configuration options

3) sudo make compiling the kernel if your computer is a multi-core can be used sudo make -jN (N is the number of nuclei of your computer)

4) sudo make modules compiled module.

5) sudo make modules_install install module

6) sudo make install to install the kernel

To install the software: 1) sudo apt-get install libncurses5-dev 2) sudo apt-get install modutils 3) sudo apt-get install kernel-package 4) sudo apt-get install build-essential

libncurses5-dev ---> when you need to use make menuconfig ncurses library support.

modutils ----> Module tools.

kernel-package ----> includes tools such as make-kpkg

build-essential -----> provide c / c ++ compiler environment, gcc, make, etc.

Now Articles password explanation!

1) Needless to say it. . . Used the command line knows.

2) where there will be the kernel configuration interface to configure the kernel. For convenience, I'm just looking for an old kernel configuration file .config ---- current system. In / lib / modules / / built directory, open the catalog, carefully you will find this is a link to the file, the actual path is / usr / src / linux-headers-version-generic folder. Copy the .config to the root directory to compile the kernel. After executing make menuconfig configuration interface in the penultimate first selected, press Save, and then select the last saved configuration, exit. If you want to manually configure, the option can be a "*", "M", digital or not selected. Use spaces can be selected, enter key to enter the sub-options. "*" Is the use of this option, while the space is not selected, "M" is this option as a module to compile. If the figures to see specific options it usually is the size of the selection. For the meaning of each option here is difficult as described! ! Too much ah! ! ! ! ! ! If you want to compile a lower version of the kernel in the 3.8 kernel, then you must manually configured. . I tried to compile successfully 2.6.39 kernel on ubuntu 3.8 kernel, 2.6.20, but it is not alright. And although it is a success, but the desktop background to display a little problem. . . . It is not recommended to compile in high version of the kernel is too low version of the kernel. There is a configuration file .config is a hidden file, you can manually edit. . It opens you will know how to modify it.

3) compile the kernel. Compiler with the usual no different, but the core is relatively large, compile time will be longer, if i5 machine it should be more than 20 minutes. . . Not carefully calculated. .

4) compile the module. There's nothing to say.

5) Install the module, here after all steps are successful, the system will generate a subdirectory under 2.6.24 / lib / modules / directory, which kept all the new kernel loadable module.

6) Install the kernel. make install to complete three major work.

1) copy the generated kernel image to / boot / directory.

2) generate initrd- < kernel-version > .img file.

3) Configure bootloader (grub or LILO), the system automatically configured for us! ! ! !

Reboot into the new kernel. In fact, here, the new kernel is enabled by default. . Because the configuration of the boot program when the new kernel should always be set as the first boot entry. In /boot/grub/grub.cfg view it. . Restart your computer, open a terminal and enter uname -r see the kernel version. . If you compile that, then congratulations. . . Success. . . . Although successful but very boring ah. . .

Below to something interesting, to modify the kernel. As mentioned above not to build low-high version of the kernel on the version of the kernel. But here I need to 2.6.22 experiment. Such a system requires the old point, you can go download system kernel older point, cenos6.4 is 2.6.32 kernel, you can try. Download 2.6.22 kernel. Here we have the kernel scheduling operation, the reason for low pay with kernel version 2.6.23 is because in the beginning of the kernel scheduling section introduces cfs, 01 dispatch (I like to call, in fact, is O (1) scheduler) began to withdraw the stage of history. Scheduling importance because linux is self-evident, and the birth of 01 scheduled for linux scheduling is a historical landmark memorial, I came into contact with the core 01 is learning begins scheduling, dispatching it took 01 to do the experiment. Because there are no cfs thoroughly understand it with scheduling section 2.6.22 to be modified. Well begun.

Modify the kernel must first find it to be corrected, because we want to modify the scheduling algorithm so we find asmlinkage void __sched schedule (void) function in the linux-2.6.22 / kernel / sched.c (approximately in the middle) to find the code in Figure :

After idx = sched_find_first_bit (array-> bitmap);

if (idx> = MAX_RT_PRIO) {

int seed = jiffies; // generate random numbers, if you want to use the random function get_random_bytes () does not work, because it generates a random number by / dev / random device.

intmod = MAX_PRIO - MAX_RT_PRIO;

seed = (seed + 7)% mod;

while (! test_bit (MAX_RT_PRIO + seed, (void) & array-> bitmap)) {

seed = (seed + 7)% mod;


idx = MAX_RT_PRIO + seed;


Save, compile and install the kernel after reboot. . . . . See what happens?
- xCAT install and update software (Linux)
- How to Install Foreman under Ubuntu (Server)
- Performance comparison Fibonacci recursive and non-recursive (Programming)
- Python control multi-process and multi-threaded concurrency (Programming)
- CentOS 6.5 x86_64 system customized automated deployment (Linux)
- Linux add a new hard disk (Linux)
- Hadoop 2.5 Pseudo distribution installation (Server)
- XtraBackup achieve non-stop use of master-slave synchronization service (Database)
- KVM QEMU virtual machine installation configuration under CentOS (Linux)
- Linux uses a screen recording under RecordMyDesktop (Linux)
- Java Foundation - The relationship between abstract classes and interfaces (Programming)
- Calling Qt libraries to implement functional processes of some summary (Programming)
- Linux based exercises, interview questions (Linux)
- Use HugePages optimize memory performance (Database)
- MySQL completely uninstall and install Configuring Character Sets under Linux (Database)
- Linux install and configure Heartbeat (Server)
- Install VMware Tools in Debian (Linux)
- Moosefs Distributed File System Configuration (Server)
- Android HTTP request with Get Information (Programming)
- Atheros AR8161 / AR8162 network card driver problem solving in CentOS 6.4 (Linux)
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.