Affirmed this article Reprinted from: http://vdata.blog.51cto.com/275084/60407
I. kernel Introduction
Kernel is the core of an operating system. It manages system processes, memory, device drivers, and files.
And network systems determine the system performance and stability.
An important feature of Linux is its open source code.
In/usr/src/Linux, most application software is designed to comply with GPL. You can obtain the corresponding source.
Program code. Any software engineer in the world can add code that he thinks is excellent.
One obvious advantage of Linux vulnerability fixing is the rapid use of the latest software technologies. In Linux
Core is the most direct representative of these features.
Imagine what the source program with the kernel means to you? First, we can understand that the system is
He's working. By reading the source code, we can understand the operating principle of the system. In Windows, this is a perfect solution.
James. Secondly, we can tailor our systems to suit our own situations, so we need
New kernel compilation. What is the situation in windows? I believe that many people are inexplicably confused by the increasing size of windows.
Expired. Again, we can modify the kernel to meet our own needs. What does this mean? That's right.
When you develop an operating system on your own, but most of the work is done, you have to add and
Implement the functions you need. In Windows, unless you are the core technical staff of Microsoft, you don't have to worry about it.
Ii. kernel version number
Since the Linux source program is completely open, anyone who follows GPL can modify the kernel concurrency.
To others. The development of Linux uses the market model (bazaar, which corresponds to the cathedral-church model ),
To ensure that these disordered development processes can be carried out in an orderly manner, Linux uses a dual-tree system. A tree is a stable tree.
(Stable tree), the other is an unstable tree or a development tree ).
Some new features and experimental improvements will be implemented in the Development tree first. You can also make improvements in the development tree.
Apply to the stability tree. after testing in the Development tree, the same improvements will be made in the stability tree. Once developed
After enough development, the development tree will become a new stable tree. The number of developers is reflected in the version number of the source program;
The source code version is in the form of x. y. Z: For the stability tree, Y is an even number. For the development tree, Y is more stable
The decision tree is one (therefore, it is an odd number ). So far, the highest version of the stability tree is 2.4.18; the latest version of the Development tree
This is 2.5.10. To download the kernel version, visit [url] http://www.kernel.org [/url].
Iii. Why re-compile the kernel?
Linux, as a free software, is constantly updated with the support of many enthusiasts. New kernel Revision
And added many new features. If you want to use these new features or
If the system customizes a more efficient and stable kernel, it needs to re-compile the kernel.
Generally, the updated kernel supports more hardware, provides better process management capabilities, and runs faster and more
Stable, and often fixes many vulnerabilities found in earlier versions, and regularly chooses to upgrade the updated System Kernel
Required operations of Linux users.
In order to correctly set the kernel compilation configuration options and compile only the functional code required by the system
There are four main considerations:
Customized and compiled kernels run faster (with less code)
The system will have more memory (the kernel part will not be exchanged to the virtual memory)
Compilation of unnecessary functions into the kernel may increase the vulnerability exploited by system attackers.
Compiling a function as a module is slower than compiling it into the kernel.
Iv. kernel compilation Mode
To support certain functions, such as networks, You can compile the corresponding parts into the kernel.
(Build-in), you can also compile this part into a module for dynamic calling. If it is compiled into the kernel,
When the kernel is started, the corresponding functions can be automatically supported. This feature is convenient and fast,
You can use this feature. The disadvantage is that it will increase the size of the kernel, no matter whether you need this feature or not,
It will exist. This is the common feature of windows. We recommend that you compile the frequently used part directly into the kernel, such as the NIC.
If it is compiled into a module, the corresponding. o file is generated and can be dynamically loaded during use. The advantage is that
The core is too large. The disadvantage is that you have to call these modules on your own.
V. Obtain and update the new kernel version
The official website for Linux kernel release is [url] http://www.kernel.org [/url]. The new version of the kernel is divided into two types:
Is the full source version, and the patch file is the patch. The complete kernel version is relatively large, generally
Tar.gz.pdf is A. bz2 file, which is compressed by gzip or Bzip2.
. The patch file is relatively small, generally only dozens of K to hundreds of K, but the patch file is for a specific version,
You must find your own version to use.
The root permission is required to compile the kernel. The following operations are assumed that you are the root user. Copy the kernel you want to upgrade
To/usr/src/(the following uses the linux-2.4.18.tar.gz of the 2.4.18 kernel as an example), the command is
# Cp linux-2.4.18.tar.gz/usr/src
Let's take a look at the current/usr/src content and notice that there is a symbolic link to the linux-2.4, pointing
A directory of A linux-2.4.7-10 (taking redhat7.2 as an example. This is the kernel source code of Linux,
Delete this link.
Decompress the downloaded source code file. If you download the .tar.gz (. tgz) file, use the following
Command:
# Tar-zxvf linux-2.4.18.tar.gz.tar.gz
If you download the. bz2 file, for example, linux-2.4.0test8.tar.bz2, use the following command
# Bzip2-D linux-2.4.18.tar.bz2
# Tar-xvf linux-2.4.18.tar
The file will be decompressed to the/usr/src/Linux directory, and we will slightly modify it:
# Mv Linux linux-2.4.18
# Ln-s linux-2.4.18 Linux
If you download a patch file, you can perform the patch operation (assuming that patch-2.4.18 is already in
/Usr/src directory, otherwise you need to copy the file to/usr/src first ):
# Patch-P0 <patching-2.4.18
6. kernel Compilation
The first command to be run is:
# Cd/usr/src/Linux
# Make mrproper
This command ensures that the source code directory does not contain the correct. o file and file dependencies. Because we use
Download the complete source program package for compilation, so this step can be omitted. If you use these source code for multiple times
To translate the kernel, run this command first.
Make sure that the ASM, Linux, and SCSI links in the/usr/include/directory point to the source code of the kernel to be upgraded.
They chain to the real, the computer architecture under the source code directory (for PC, the system
I386. For example, ASM points to/usr/src/Linux/include/asm-i386
. If you do not have these links, you must create them manually. follow these steps:
# Cd/usr/include/
# Rm-r ASM Linux SCSI
# Ln-S/usr/src/Linux/include/asm-i386 ASM
# Ln-S/usr/src/Linux/include/Linux
# Ln-S/usr/src/Linux/include/SCSI
This is an important part of configuration. Delete the ASM, Linux, and SCSI links under/usr/include, and then
Create a new link pointing to a directory with the same name under the new kernel source code directory. These header file directories contain
The important header files required for correct compilation on the system. Now you should understand why we are in/usr/src again.
I have created a link named Linux?
The subsequent Kernel configuration process is cumbersome, but the proper configuration is directly related to Linux running in the future,
It is necessary to understand some of the main and frequently used options.
You can use one of the following commands to configure the kernel based on your needs and hobbies:
# Make config (the most traditional text-based configuration interface is not recommended)
# Make menuconfig (Text menu-based configuration interface, recommended for character terminals)
# Make xconfig (the configuration interface based on the graphic window mode is recommended in XWindow)
# Make oldconfig (if you only want to modify some small points based on the original Kernel configuration, it will save a lot of trouble)
The Make xconfig interface is the most user-friendly among the three commands. If you can use XWindow, we recommend that you
You can run the following command on the interface:
If you cannot use XWindow, use make menuconfig. Although the interface is worse than the above one
Point, it is always much better than make config, For the make menuconfig interface:
When you select the corresponding configuration, there are three options, which represent the following meanings:
Y -- compile this function into the kernel
N -- do not compile this function into the kernel
M -- compile this function into a module that can be dynamically inserted into the kernel as needed
If you are using make xconfig, you can select the corresponding option with the mouse. If you are using
Make menuconfig, you need to use the space key for selection. You will find a bracket in front of each option,
Some square brackets, some square brackets, and some square brackets. When using the space key, you can find that either
Is empty, or "*", and the angle brackets can be empty, "*" and "m ". This indicates that the items corresponding to the former are either not or
Compile the program to the kernel. The latter can be compiled into modules in the same way. The content of parentheses is what you provide
Select one of the following options.
In the process of compiling the kernel, the most annoying thing is the configuration work in this step. Many new users do not know whether
Select these options. In fact, the default value can be used for most options during configuration. Only a small part of the options need to be
Select based on different user needs. The principle of selection is that it will be far away from other parts of the kernel and is not frequently used.
The ability to compile code into a loadable module helps reduce the length of the kernel, reduce the memory consumption of the kernel, and simplify this function.
The impact on the kernel when the corresponding environment changes; do not select features that are not required; be closely concerned with the kernel and often used
Some of the functional code is directly compiled into the kernel.
As for the options, it is complicated, just a brief introduction. The compilation should be based on the specific situation, refer to the Help content and then
Select.
1. Code maturity level options
Code maturity level. There is only one item here: Prompt for development and/or incomplete code/drivers,
If you want to test functions that are still in the experiment stage, such as khttpd and IPv6, You must select y as the option;
Otherwise, you can select n.
2. loadable module support
Module support. There are three items:
Enable loadable module support: This item is required unless you want to compile all required content into the kernel.
Set version information on all module symbols: Optional.
Kernel module Loader: enables the kernel to load required modules at startup. We recommend that you select this module.
3. Processor type and features
CPU type. There are a lot of content. I will not introduce them one by one. The following are some of the relevant content:
Processor family: select the CPU type based on your situation.
High memory support: supports large memory capacity. It can be 4 GB or 64 GB.
Math emulation: coprocessor simulation. Coprocessor is the darling of the 386 age and is no longer needed.
MTTR support: supported by MTTR. Optional.
Hierarchical Ric multi-processing support: supports Symmetric Multi-processing. Unless you are rich enough to have multiple CPUs, you do not need to choose.
4. General setup
Here are some of the most common attributes. This part contains a lot of content. Generally, you can use the default settings. The following describes some frequently used options:
Networking Support: network support. Required. We recommend that you select this option if no network adapter is available.
PCI support: supports PCI. If the PCI Card is used, it is required.
PCI access mode: PCI access mode. Options include bios, direct, and any. Select any.
Support for hot-pluggabel devices: supports hot swapping devices. It is not very good to support.
PCMCIA/carw.support: PCMCIA/carw.support. PCMCIA is required.
System V IPC
BSD process accounting
Sysctl support: the above three types of support are related to process processing and IPC calls, mainly System V and BSD. If you are not using BSD, follow the default setting.
Power Management Support: power management support.
Advanced Power Management BIOS support: Advanced Power Management BIOS support.
5. memory technology device (MTD)
MTD device support. Optional.
6. Parallel Port support
Parallel Port support. If you do not want to use the serial port, do not select it.
7. Plug and Play Configuration
Plug-and-play is supported. Although plug-and-play in Linux is not as good as that in Windows currently, you can choose it. In this way, you can unplug the mouse and try plug-and-play in Linux.
8. Block devices
Block device support. You have to select one based on your own situation. Here is a brief description:
Normal PC floppy disk support: general PC floppy disk support. This should be required.
XT hard disk support:
Compaq smart2 support:
Mulex dac960/dac1100 pci raid Controller support: For raid images.
Loopback device support:
Network block Device Support: supported by network Block devices. If you want to access the Internet neighbors, choose.
Logical Volume Manager (LVM) support: logical volume management support.
Multiple devices driver support: supports multiple device drivers.
RAM disk support: ramdisk support.
9. Networking options
Network options. The network protocol is configured here. There is too much content. I will not introduce it one by one. Let's take a look at it. If you have some knowledge about network protocols, you should be able to understand it. If you are too lazy to check the network, use the default option (You must select the TCP/IP networking option. Let's take a look at TCP/IP, ATM, IPX, decnet, appletalk ...... Many protocols are supported, IPv6 is also supported, QoS and/or fair queueing is also supported, and khttpd is also supported, but these are still in the experimental phase.
10. telephony support
Phone support. Linux supports phone cards, so that you can use a common phone on an IP address to provide voice services. Remember, the phone card has nothing to do with modem.
11. ATA/IDE/MFM/rll support
This is supported by hard disks, optical drives, tapes, and floppy disks with many interfaces. Use the default options. If you use special devices, such as PCMCIA, find the corresponding options.
12. scsi support
Support for SCSI devices. I don't have a SCSI device, so I don't need to select it. If you use a SCSI hard drive, optical drive, tape, and other devices, you can find them yourself.
13. Fusion MPT Device Support
Fusion MPT compatible with PCI adapter is required.
14. i2o Device Support
The i2o interface adapter is required for use in Intelligent Input/output (i2o) system interfaces.
15. Network Device Support
Network Device Support. I have selected the Protocol above. Now I have to select a device. As you can imagine, the content must be much more. Fortunately, it is probably classified into ARCNET devices, Ethernet (10 or 100 Mbit), Ethernet (1000 Mbit), and wireless LAN (non-hamradio), Token Ring device, Wan interfaces, and pcmcia network device support. I use 10/100 M Ethernet. It seems that I only need to select this one. Or 10/100 M Ethernet device familiar, although the content is much, at a glance can see my realteck RTL-8139 PCI Fast Ethernet Adapter support, in order to avoid trouble, compiled into the kernel is good, if M is not selected, select y. Be patient. Generally, you can find your own network card. If not, you have to go to the vendor to get the driver.
16. Amateur Radio support
Configure amateur Wireless broadcast.
17. IrDA (infrared) Support
Infrared support.
18. ISDN Subsystem
If you use ISDN to access the Internet, this is essential.
19. Old CD-ROM drivers (not SCSI, not IDE)
Do really thoughtful, originally those who are not SCSI/ide optical drive who is still using ah, choose it yourself, with IDE CD-ROM don't have to choose.
20. Character Devices
Character device. This content is too much. Use the default settings first, and modify the content as needed. Let's introduce the main categories:
I2C support: I2C is a low-speed serial bus protocol used in micro-control applications promoted by Philips. This option is required if you want to select the following video for Linux.
Mice: Mouse. Now you can select bus, serial port, PS/2, C & T 82c710 mouse port, and pc110 digitizer pad as needed.
Joysticks: handle. Even if you drive the handle in Linux, it doesn't make much sense, and there are too few games.
Watchdog cards: although it is called cards, it can be implemented with pure software, and of course there are hardware. If you select this option, a file named watchdog will be created under your/dev, which can record the running status of your system, it takes about 1 minute to restart the system. With this file, you can restore the system to the state before restart.
Video for Linux: audio/video cards are supported.
Ftape, the floppy tape device driver:
PCMCIA character device support:
21. File Systems
File System. There are too many contents. The old method is to modify the content based on the default options. This section describes the following items:
Quota support: quota can limit the maximum disk space available to each user, which is very effective when multiple users share a single host.
Dos fat FS Support: supports the format of dos fat files, including fat16 and FAT32.
ISO 9660 CD-ROM file system support: the disc uses the ISO 9660 file format.
NTFS file system support: NTFS is the file format used by NT.
/Proc file system support:/proc file system is a channel provided by Linux for users to interact with the system. It is recommended that you select it. Otherwise, some functions cannot be correctly executed.
The other three categories are here: network file systems (Network File System), partition types (partition type), and Native Language Support (local language support ). It is worth mentioning that there are two types of network file systems: NFS and SMB, respectively, Linux and Windows, access each other's file systems in the form of network neighbors, and select as needed.
22. Console drivers
Console driver. Generally, you can use the VGA text console, the standard 80*25 text console.
23. Sound
Sound Card Driver. If you can find the sound card driver in the list, it is naturally best, otherwise you will try OSS.
24. USB supprot
USB support. Many USB devices, such as the mouse, modem, printer, and scanner, can be supported in Linux and can be selected as needed.
25. kernel hacking
With this configuration, you can do some work even when the system crashes. Common users do not need this function.
After the configuration, save the disk and exit. Of course, you can save the current configuration file so that the next configuration will save effort.
Next, compile and enter the following command.
# Make Dep
# Make clean
# Make bzimage or make zimage
# Make modules
# Make modules_install
# Depmod-
The first command, make DEP, actually reads the configuration file generated during the configuration process to create the dependency tree corresponding to the configuration, so as to determine which need to be compiled and which do not need to be; the second command is make clean to delete the files left in the previous step to avoid some errors. Make zimage and make bzimage are used to fully compile the kernel, and Gzip is used to compress the kernel generated by both, one is enough. The difference between them is that make bzimage can generate a larger kernel. We recommend that you use the make bzimage command.
The following three commands are necessary only when you answer enable loadable module support (config_modules) in the configuration process, make modules and make modules_install generate the corresponding modules and copy the modules to the required directories.
Strictly speaking, the depmod-a command has nothing to do with the compilation process. It is used to generate dependencies between modules. After you start the new kernel, the module can be correctly located when the module is loaded using The modprobe command.
Update
After the above steps, we finally get the new kernel version. To be able to use the new kernel version, we also need to make some changes:
# Cp/usr/src/Linux/system. MAP/boot/system. Map-2.4.18
# Cp/usr/src/Linux/ARCH/i386/bzimage/boot/vmlinuz-2.4.18
The above two files are newly generated during compilation. Next, modify the two links system. Map and vmlinuz under/boot to point them to the new kernel file:
# Cd/boot; RM-F system. Map vmlinuz
# Ln-s vmlinuz-2.4.18 vmlinuz
# Ln-S system. Map-2.4.18 system. Map
7. Modify the startup Manager
If lilo is used, modify/etc/Lilo. conf and add the following items:
Image =/boot/vmlinuz-2.4.18
Label = linux240
Read-Only
Root =/dev/hda2
The root =/dev/hda2 line must be modified as needed.
Run:
#/Sbin/lilo-V
Make sure that you have edited/etc/Lilo. conf correctly. Now restart the system:
# Shutdown-R now
If you use grub to start the manager, add the following items.
Title Red Hat Linux (2.4.18)
Root (hd0, 0)
Kernel/vmlinuz-2.4.18 Ro root =/dev/hda2
Grub automatically takes effect without calling the command again.
After the restart, you can use the new kernel.