Basic kernel knowledge and kernel upgrade

Source: Internet
Author: User
Basic kernel knowledge and kernel upgrade-general Linux technology-Linux programming and kernel information. For details, refer to the following section. The kernel is the core part of the entire * Operating System. It manages communication between hardware, determines which process is running, and provides a relatively isolated virtual address space required for each process to run. The kernel is loaded into the system by the boot program (grub, lilo. The kernel is responsible for loading drivers and modules into the system. After compiling the kernel, you can bring the following benefits:
Greatly improve the running speed of core services
Provides direct support for the kernel of the service specified by the user Server
Dynamic support for appropriate services in modular form
By reducing unnecessary services, you can reduce the memory requirements of the kernel.
Configuration supports high-end hardware, such as memory larger than 4 GB, hard disk array, symmetric multi-cpu
Suggestions for compiling the kernel:
Compile the kernel only when necessary and directly compile it into the kernel
The less things the faster the system runs. If you do not need a sound card, you can remove the support for the sound card from the kernel. By removing unnecessary devices, you can reduce the kernel and increase the system running speed without changing the device. Leave more available resources for other hardware.
In general, it is
Better Way. The module is an extension of the kernel. Although it is not directly compiled into the kernel, it can be loaded and detached as needed.
Kernel Concept:
The system administrator should have a certain understanding of the system kernel to better compile the kernel.
Single Kernel and modular Kernel
Single Kernel: All device modules are directly compiled into the kernel.
Modular kernel: many devices are loaded separately in the form of modules
The communication speed between a single kernel and a device is fast. The modular kernel and hardware need to communicate through the module list. However, the single kernel is too large. The large kernel reduces the available memory. Some systems cannot even start such a large kernel. In the past, Linux used a single kernel, which was once faulty by some hardware when loading a modular kernel. With a single kernel, all the drivers are installed after the system is installed. The modular Kernel provides great flexibility. You can compile almost all drivers as modules, so that these modules will be loaded into the system when necessary. Modularization makes the kernel very small, which reduces the time required to start and improves the overall system performance.
If a problem occurs during linux module loading, you can use modprobe or
The insmod command to manually load the module.
Upgrade the kernel: merging within the upgrade is not as difficult as it looks. You should always keep the kernel for a long time to avoid system boot failure due to new Kernel errors. For grub or lilo, the new kernel is a new * Operating System. If a new kernel is installed using the rpm package, the boot program is automatically upgraded. If you make a big mistake and cannot boot, you can choose to use the old kernel after restarting. You should save the Kernel configuration file so that you can easily copy it to the new kernel for further use. Details will be detailed in subsequent sections.
/Boot directory:
The linux kernel is stored in this directory. The new kernel must also be stored in this directory for use. This directory is 100 MB, enough to store the current kernel and the additional kernel during kernel upgrade.
/Proc
Directory: This directory is based on a virtual file system. In other words, she does not contain any files stored on the hard disk, but it is a window for viewing the computer. If you want to view the current memory information, run the following command: cat
/Proc/meminfo
Ip forwarding: view the current status: cat
/Proc/sys/net/ipv4/ip_forward. If the output is
1. This function is enabled. If it is 0, it is not enabled.
Enable ip forward: echo 1
>/Proc/sys/net/ipv4/ip_forward
Prevent ping of death attacks: # echo 1>
/Proc/sys/net/ipv4/tcp_syncookies
Understand the kernel module:
When you compile the kernel, You can compile all the required drivers into the kernel to become a single kernel. However, this kernel is too large and takes a long time to load. Most system administrators use kernel modules. The kernel module is not directly compiled into the kernel, but Dynamically Loaded and uninstalled as needed. In addition to the hardware related to the kernel module, you can use kudzu. This is an automatic detection and Configuration tool. Generally, it runs automatically when the system is started. Of course, you can also manually run this tool to eliminate faults. Kmod is a module loading controller responsible for loading and uninstalling kernel modules. You can modify the/etc/modules. conf file by specifying a special peaceful parameter. Most hardware can be detected automatically. For unrecognized hardware, run depmod.
? A
Manual module loading: modprobe example: # modprobe pcnet32
View the currently loaded modules: # cat
/Proc/modules or # lsmod
Uninstall module: rmmod? R pcnet32

Upgrade the kernel

1. About the kernel version
The kernel version is generally in the following format: x. x. x For example: 2.4.21
The first digit indicates the primary version number, the second digit indicates the secondary version number, and the third digit indicates the patch number. Major version changes often mean a huge change, and many programs may not be able to use the new kernel. The secondary version has two meanings: The x version of the first main version of the kernel. If the second x is an odd number, the kernel version is in development and is not suitable for production, if it is an even number, it indicates that the version is a stable and reliable version and can be used for production. The last number indicates the patch version.
2. Upgrade the kernel
New kernels often contain new technologies, which means that the system can support more devices and better stability and faster performance. Therefore, the system administrator may need to upgrade the kernel. There are two main methods to upgrade the kernel:
1,
The rpm package Upgrade Method downloads compiled rpm kernel software from the Internet
Package, and then install it, for example, rpm? Ivh
Kernel-2.4.21-8.i386.rpm
2. Use the source code package of the kernel for compilation and installation.
This part is more complex.
This section is described in detail.
3. kernel patch
To make your system run more stable and efficient, you may often need to patch your system, for example, from 2.4.20 to 2.4.21. Kernel patches can be easily downloaded from the Internet. Installation is also very easy, for example:
# Zcat
Pathch-2.4.22.gz | patch? P0
3. Create boot Disks
# Mkbootdisk
"Current kernel version number"
Example: mkbootdisk 2.4.20
# Dd if =/mnt/cdrom/images/bootnet. img
Of =/dev/fd0
Create and Install Boot disks from the CD
4,
Kernel resources
One of the advantages of linux is that you can adjust
To make it meet your needs. To compile the kernel, you must first understand the linux source code. Once the source code package is installed, you will see the following sub-directories in the/usr/src directory:
Debug, redhat, linux-2.4, linux-2.4.21-4.EL. The linux-2.4 is the symbolic link file for the linux-2.4.21-4.EL. Run the following command to install the kernel source code package:
# Mount
/Mnt/cdrom
# Rpm? Uvh/mnt/cdrom/RedHat/RPMS/kernel-source -*
Or you can download linux
Tar file, which is the source code package released in the form of tar.gz.
4. recompile the kernel
Decompress the downloaded kernel to the/usr/src/directory.
# Cd
/Usr/src/enter this directory
# Ln linux-2.4.26 linux-2.4 creates a symbolic link file for this directory
# Cd linux-2.4
Enter the kernel directory
Modify the Makefile file and find the line that contains EXTAVERSION to EXTRAVERSION = qun.
# Make mrproper
Ensure consistency of source files
# Make xconfig select the function to be compiled into the kernel
# Make dep solves dependencies
# Make bzImage
Generate Kernel
# Make modules compile the kernel module
# Cp usr/src/linux-2.4/arch/i386/boot/bzImage
/Boot/vmlinuz-2.4.26qun
# Make modules_install install the kernel module
# Mkinitrd
/Boot/initrd-2.4.26qun.img 2.4.26qun generate boot Image File
# Cp
/Usr/src/linux-2.4/System. map/boot/System. map-2.4.26qun
# Vi/etc/grub. conf #
Add the following lines in the last part:
Title Red Hat Linux (2.4.26qun)
Kernel/vmlinuz-2.4.26qun ro
Root = LABEL =/
Initrd/initrd-2.4.26qun.img
: Wq!
# Reboot
After restarting, you can see the installed kernel.
# For the 2.6 kernel, the steps are much simpler. You only need the following commands:
Make xconfig, make, make
Install

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.