Transfer from Embedded Information Network
Kernel Introduction
Kernel is the core of an operating system. It manages system processes, memory, device drivers, files, and network systems, and determines system performance and stability.
An important feature of Linux is its open source code. All kernel source programs can be found in/usr/src/Linux. Most application software is designed to comply with GPL, you can obtain the source code.
Any software engineer in the world can add code that he thinks is excellent. One obvious benefit of this is the fast fixing of Linux vulnerabilities and the use of the latest software technology. The Linux kernel is the most direct representative of these features.
Imagine what the source program with the kernel means to you? First, we can understand how the system works. By reading the source code, we can understand the operating principle of the system, which is simply a fantasy in windows. Secondly, we can tailor the system to suit our own situation, so we need to re-compile the kernel.
What is the situation in windows? I believe that many people have been inexplicably confused by the increasing size of windows. Again, we can modify the kernel to meet our own needs. What does this mean? Yes, it is equivalent to developing an operating system on your own, but most of the work is done. All you have to do is 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.
Kernel version number
Since the Linux source program is completely open, anyone who follows GPL can modify the kernel and publish it 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.
One tree is a stable tree, and the other is a non-stable tree or a development tree ). Some new features and experimental improvements will be implemented in the Development tree first. If the improvements made in the Development tree can also be applied to the stability tree, the same improvements will be made in the stability tree after tests in the Development tree. Once the development tree has been sufficiently developed, the development tree will become a new stable tree.
The development number is reflected in the source program version number. The source program version number is in the form of X. y. z: for a stable tree, Y is an even number. For a development tree, Y is bigger than the corresponding stable tree (therefore, it is an odd number ). So far, the maximum version of the stability tree is 2.2.16. The latest release of redhat7.0 adopts the 2.2.16 kernel, and the latest version of the Development tree is 2.3.99. Maybe you have found and many websites have a kernel like 2.4.0-test9-pre7, but this is not the official version. Kernel updates allow access to the http://www.kernel.org.
Why re-compile the kernel?
Linux, as a free software, is constantly updated with the support of many enthusiasts. The new kernel fixes bugs in the old kernel and adds many new features. If you want to use these new features or customize a more efficient and stable kernel based on your system, you need to recompile the kernel.
Generally, the updated kernel supports more hardware, provides better process management capabilities, and runs faster and more stably. It also fixes many vulnerabilities found in earlier versions, it is necessary for Linux users to regularly upgrade and update the system kernel.
In order to correctly set the kernel compilation configuration options and compile only the code of the functions required by the system, the following four considerations are generally taken:
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.
Kernel compilation Mode
To support a certain part of functions, such as the network, you can compile the corresponding part into the kernel (build-in) or compile the part into a module ), dynamic call.
If it is compiled into the kernel, the corresponding functions can be automatically supported when the kernel is started. This advantage is convenient and fast, and the machine starts once, you can use this feature. The disadvantage is that it will make the kernel huge. Whether you need this feature or not, it will exist. This is the common practice of windows, we recommend that you compile the frequently used parts directly into the kernel, such as the NIC.
If it is compiled into a module, the corresponding. o file will be generated and can be dynamically loaded during use. The advantage is that the kernel will not be too large, but you have to call these modules by yourself.
Kernel compilation details
Obtain and update the new kernel version
Linux Kernel version released on the official website is http://www.kernel.org, China's major FTP can generally find some versions of the kernel. The new version of the kernel is released in two forms: one is the complete kernel version, and the other is the patch file, that is, the patch.
Compared with linux-2.4.0-test8.tar.bz2, the website has a large number of cores, which can be downloaded and used by users with fast network speeds. The internal kernel is generally a .tar.gz(.tgz.pdf file, which is a. bz2 file. The two files are compressed using gzip or Bzip2, and need to be decompressed during use.
Patch files are relatively small, generally only dozens of K to hundreds of K, and rarely exceed 1 M. Users with slow network speeds can use patch files to upgrade the kernel. However, the patch file is for a specific version. You need to find your own version to use it.
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 linux-2.4.0test8.tar.gz of the kernel 2.4.0test8as an example). The command is
# Cp linux-2.4.0test8.tar.gz/usr/src
Let's take a look at the current/usr/src content and notice that there is a Linux Symbolic Link that points to a directory similar to a linux-2.2.14 (corresponding to the kernel version you are using now. First, delete the link:
# Cd/usr/src
# Rm-F Linux
Decompress the downloaded source code file. If you download the .tar.gz (. tgz) file, use the following command:
# Tar-xzvf linux-2.4.0test8.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.0test8.tar.bz2
# Tar-xvf linux.2.4.0.test8.tar
Now let's take a look at the content under/usr/src. Now you will find that there is a directory named Linux, which contains the source program of the kernel we need to upgrade. Do you still remember the link named Linux? The reason for using that link is to prevent the source program of the original kernel version from being overwritten during kernel upgrade. We also need to handle the same problem:
# Mv Linux linux-2.4.0test8
# Ln-s linux-2.4.0test8 Linux
In this way, we also have a symbolic link named Linux, so you don't have to worry about overwriting it in the future (maybe you will feel that it is unnecessary to re-establish a Linux Symbolic Link, but in fact this is essential, which will be introduced below ). If you also download the patch file, such as the patch-2.4.0test8, you can perform the patch operation (assuming that the patch-2.4.0test8 is already in the/usr/src directory, otherwise, you need to copy the file to/usr/src first ):
# Patch-P0 <patch-2.4.0test8
Now we have upgraded the kernel source program to the latest version. Let's start the kernel compilation journey.
Preparations
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. This step can be omitted because we use the downloaded full source program package for compilation. If you use these source programs to compile the kernel multiple times, you 'd better 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 the real include sub-directories required by the real computer architecture (i386 for PCs) under the source code directory.
For example, ASM points to/usr/src/Linux/include/asm-i386 and so on. 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 the directory with the same name under the new kernel source code directory. These header file directories contain the important header files required to ensure that the kernel is correctly compiled on the system. Now you should understand why we have created a link named Linux in the "redundant" Directory of/usr/src?
Configuration
The following Kernel configuration process is cumbersome, but the proper configuration is directly related to Linux running in the future. It is necessary to know 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)
Among the three commands, the make xconfig interface is the most friendly. If you can use XWindow, we recommend that you use this command.
If you cannot use XWindow, use make menuconfig. Although the interface is worse than the previous one, it is better than make config.
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 to select. You will find that there is a bracket before each option, but there are brackets, angle brackets, and parentheses.
When using the space key, you can find that the brackets are either empty or "*", while the angle brackets can be empty, "*" and "m" indicate that the items corresponding to the former are either not required or compiled into the kernel. The latter selects the same item and can be compiled into modules. The content of the parentheses is to select one of the options provided.
In the process of compiling the kernel, the most annoying thing is the configuration work in this step. Many new users do not know how to choose these options. In fact, the default value can be used for most options during configuration. Only a small part of options need to be selected based on different user needs.
The selection principle is to compile some functional code that is far away from other parts of the kernel and is not frequently used into a loadable module, which helps reduce the length of the kernel and reduce the memory consumption of the kernel, the impact on the kernel when the corresponding environment change of this function is simplified; do not select a function that is not required; compile some function code that is closely related to and frequently used by the kernel directly into the kernel. Next let's introduce the common options separately.
1. Code maturity level options
Code maturity level. There is only one item: Prompt for development and/or incomplete code/drivers. If you want to test functions that are still in the experimental stage, such as khttpd and IPv6, you must select Y. 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 is to set 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 biod support.
5. memory technology device (MTD)
MTD device support. Optional.
6. Parallel Port support
Serial 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. What is this? Let me check the help. It turns out that Linux supports phone cards, so that you can use a common phone to provide voice services on an IP address. 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. What is IEEE 1394 (FireWire) support? I have never seen any earlier version. Let's look at the help. I used to use fireware hardware to improve the performance of the serial bus. I did not select it.
14. i2o Device Support
This is not clear. In the help section, it is said that the i2o interface adapter is required to support this function. It is used in Intelligent Input/output (i2o) system interfaces and hardware is required.
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
If you don't understand it, you should configure amateur wireless broadcasting. No, no.
17. IrDA (infrared) Support
This requires infrared support.
18. ISDN Subsystem
If you use ISDN to access the Internet, this is essential. I have done it myself.
19. old CD-ROM drivers (not SCSI, not IDE) do really thoughtful, the original thOSe non SCSI/ide ports who are still using the drive ah, choose it, anyway, I am using the IDE CD-ROM, don't choose this.
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.
There are also three other categories: network file systems, partition types, and native 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 is complete, save the disk and exit. Of course, you can save the current configuration file so that you can save the effort to configure it again next time.
Compile
After complicated configuration, you can wait for a cup of tea. Compilation-related Commands include the following:
# Make Dep
# Make clean
# Make zimage
# Make bzimage
# 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; run the second command make clean to delete the files left in the previous step to avoid some errors. Run the Third Command make zimage and the fourth command make bzimage to fully compile the kernel, both of them use gzip to compress the kernel. The difference is that make bzimage can generate a larger kernel, for example, if you use the make zimage command to compile the kernel of version 2.4.0, the system too big error message will appear. 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 seventh 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.0test8
# Cp/usr/src/Linux/ARCH/i386/bzimage/boot/vmlinuz-2.4.0test8
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.0test8 vmlinuz
# Ln-S system. map-2.4.0test8 system. Map
Then modify/etc/Lilo. conf:
# Vi/etc/Lilo. conf
Add the following section:
Image =/boot/vmlinuz-2.4.0test8
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
Press the tab key and enter linux240 when lilo appears after the machine is restarted. Our new kernel plays a role. Enjoy it.