Reading Notes on "laruence's Linux house dish": Linux kernel compilation and management

Source: Internet
Author: User
Tags gtk

Reading Notes on "laruence's Linux house dish": Linux kernel compilation and management
1. kernel introduction and obtain kernel source code 1.1 What is kernel: kernel is the bottom layer of the entire operating system and is responsible for the entire hardware driver, and provides the kernel functions required by various systems, including firewall mechanisms, whether to support LVM, Quota, and other file systems. If your kernel cannot identify the latest hardware, it cannot be driven, and you certainly cannot use it.In fact, the kernel is just a file on the system. This file contains the detection program and driver module for various hardware of the driver host.Kernel files are generally stored in the/boot/vmlinuz directory. The Kernel module is used to extract some uncommon drivers from the Kernel and compile them into modules, without replacing the kernel and re-compiling the kernel, the kernel can load this module to the kernel during normal system operation. The directory is/lib/modules/$ (uname-r)/kernel/1.2. Why is the kernel updated?

Kernel compilation focuses onWhat do you want your Linux to do.If you do not need to work, you do not need to add it to your kernel! In this way, Linux can run more stably and smoothly. That's why weThe main reason for compiling the kernel.

Possible purpose of kernel Compilation:
Requirements for new features the original kernel is too bloated and the stability of the hardware mix other requirements (such as embedded systems)

Although re-compiling the kernel can optimize your hardware, these optimization steps have little impact on the overall performance. Therefore, if you want to increase the performance to compile the kernel, basically, the benefits are not great. HoweverSystem StabilityTo recompile the kernel. Because the main task of the kernel is to control the hardware, before compiling the kernel, please first understand your hardware configuration and the future features of your host. Because the kernel isThe simpler the betterSo the hacker just needs to compile the future functions of this host.

1.3 kernel source code extraction, installation, and observation of kernel source code decompression and placement Directory: the kernel source code is generally recommended under the/usr/src/kernels/directory. Tar-jxvf linux-X.X.XX.X.tar.bz2-C/usr/src/kernels/. A new directory is generated under/usr/src/kernels, which is the linux-X.X.XX.X directory. Directory under the kernel source code:
Arch: Most projects related to the hardware platform refer to the CPU category, such as x86, x86_64, and Xen virtual support. Block: Set data related to the device group. block data usually refers to mass media storage. It also includes whether ext3 and other file systems are supported or not. Crypto: Encryption technologies supported by the kernel, such as md5 or des. Documentation: A bunch of instruction files related to the kernel. If you are very interested in the kernel, check it out here. Drivers: Some hardware drivers, such as display adapters, network cards, and PCI-related hardware; Firmware: Some Old-style hardware micro-script (firmware) data; Fs: Filesystems supported by the kernel, such as vfat, reiserfs, and nfs; Include: Some headers that can be called by other processes define data; Init: Some kernel initialization definition functions, including mounting and calling of init programs; Ipc: Defines the communication between various programs in the Linux operating system; Kernel: Defines the kernel program, Kernel Status, thread, program schedule (schedule), program signal (signle), etc. Lib: Some function libraries; Mm: Data related to memory units, including swap and virtual memory; Net: Network-related protocol data, as well as firewall modules (net/ipv4/netfilter; Security: Security settings including selinux; Sound: Audio-related modules; Virt: Information related to Virtual machines. Currently, the Kernel supports KVM (Kernel base Virtual Machine)

This data will give a general impression first, at least in the future, if you want to use the patch method to add additional new features, where do you want to put your source code, here we can provide some guidance. Of course, it is better to go to the Documentation directory and check the correct description, which will be more helpful for your kernel compilation.

2. Pre-processing of kernel compilation and selection of kernel functions

Purpose of the kernelIt is about managing hardware and providing system core functions. Therefore, you must first find your system hardware and plan your host's future tasks, in this way, the kernel suitable for your host can be compiled. Therefore, it is important to compile the entire kernel.Select the desired feature.

2.1 hardware environment view and core function requirements hardware environment view: Use/proc/cpuinfo and lspci to observe 2.2 keep the source code clean: make mrproper

After learning about hardware-related data, we have to process the residual files under the kernel source code. If this is the first compilation, but we do not know whether the target file is retained in the downloaded source code (*. o) and related configuration files exist. In this case, we can use the following commands to process the target files and configuration files of the compilation process:Make mrproper
This command also deletes the core function Selection file that you have previously selected, so this operation is performed almost only before the first core compilation, and the rest of the time, to delete the residual data in the previous compilation process, release: make clean

2.3 start to select the core function: make XXconfig

/Boot/There is a file named config-xxx under it. That file is actually a list of core functions. The operation we are going to perform is actually to make this file. The subsequent compilation operations are actually handled through this file. The selection of core features will finally generate a hidden file named. config under/usr/src/kernels/linux-X.X.XX.X/, which is the file of/boot/config-xxx. You can create this file in many ways. The common methods are as follows:

Make menuconfig:The most commonly used mode is that similar graphical interfaces can be displayed in text mode. You do not need to start X Window to select the core function menu. Make oldconfig:Use existing. /. config File Content. Use the default value in the file to list the new feature options in the core of the new version for the user to select. This simplifies the selection of core features! As a feature selection after upgrading the core source code, it is a very useful project! Make xconfig:The graphical interface display based on the basic functions of the Qt graphic interface requires the support of X window. For example, KDE is the X Window designed through Qt, so you can use this project in the KDE screen. Make gconfig:The graphic interface display based on the basic functions of Gtk graphic interface requires the support of X window. For example, GNOME is the X Window designed through Gtk, so you can use this project in the GNOME screen. Make config:The oldest function Selection Method. Each project is listed in a column for you to choose from. If the setting is incorrect, you can only select again. It is not recommended. 2.4 for details about how to configure the core functions, refer to laruence's linux private DISH 3. to compile and install the kernel, 3.1 compile the kernel and the kernel module first. You can use Make helpCheck all the available compilation parameters to see the following basic functions:
Make vmlinux # uncompressed Core Make modules# Only Kernel Modules Make bzImage# Compress the core (default) make all # perform the above three operations:
Make clean # Clear the temporary archive make bzImage # compile core make modules # compile module 3.2 actual installation Module

We know that the modules are placed in the/lib/modules/$ (uname-r) directory. If the modules of the same version are repeatedly compiled and installed later, conflicts will occur. Solution:

First, rename the old Module Directory, and then install the core module to the target directory. When making menuconfig, change the Local version in the General setup to a new name.

Install the module to the correct target directory:Make modules_installIn the end, the relevant modules of your core will be established under/lib/modules.

3.3 start to install the new core and multi-core menu (grub) Move the core to/boot and keep the old Core File
Cp/usr/src/kernels/linux-X.X.XX.X/arch/x86/boot/bzImage/boot/vmlinuz-X.X.XX.XXXX# Actual Kernel Cp/usr/src/kernels/linux-X.X.XX.X/. config/boot/config-X.X.XX.XXXX# Create an Initial Ram Disk (initrd) corresponding to the backup configuration file ): Mkinitrd-v/boot/initrd-X.X.XX.XXXX.img X. X. XX. XXXXEdit the boot menu (grub): Edit /Boot/grub/menu. lst(For specific configuration, refer to) Summary: Kernel compilation steps and kernel deletion kernel compilation steps:
First download the kernel source code (such as SPRM) and then use the Tarball to process it. Unlock the original code and delete the old data in the/usr/src/kernels Directory: make mrproper starts to select the core functions, you can use make menuconfig, make oldconfig, make gconfig, and so on to clear the intermediate temporary disk information: make clean to start compiling the Kernel File and kernel module: make bzImage and make modules start kernel module installation: make modules_install start Kernel File Installation, which can be used in the following ways: make install or manually copy the core file to/boot/grub to create an initrd file; Modify/boot/grub/menu. delete the lst file kernel:
First, you can delete the source code: rm-rf/usr/src/kernels/linux-X.X.XX and then delete the kernel module Directory: rm-rf/lib/modules/X. x. XX finally deleted the kernel files and initrd files in/boot/AND/boot/grub/menu. you can set the title in the lst.

Related Article

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.