Step by step to teach you how to become a LINUX expert-Cainiao to compile the kernel

Source: Internet
Author: User
Article title: Teach you how to become a LINUX expert step by step-Cainiao compiles the kernel. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
  
   Download source code
Linux kernel is always evolving. The latest kernel kernel2.6.0 officially supports USB2.0, and the most significant change in kernel module file suffix is *. o *. ko and so on. we can download the tarball source code package from www.kernel.org.
  
   Preparations
We all know that we need to upgrade the "module-init-tools" package first. otherwise, when you install the kernel module file, the system will prompt you: Warning: you may need to install module-init-tools See http://www.codemonkey.org.uk/post-h...4.21-23.src.rpm
Go to the download directory and install:
# Rpm-e -- nodeps modutils (force uninstall the original modutilsRPM package)
# Rpm-ivh modutils-2.4.21-23.src.rpm (install the source code package to the/usr/src/redhat directory)
# Cd/usr/src/redhat/SPECS (go to the standard file directory)
# Rpmbuild -- bb modutils. spec (generate a binary RPM Package)
# Cd ../RPMS/i386 (transfer to the location of the generated binary RPM Package)
# Rpm-ivh modutils *. rpm (just generate two [modutils-2.4.21-23.i386.rpm & modutils-debuginfo-2.4.21.23.i386.rpm] binary RPM packages, install them together !)
Because it is on the RedHat9.0 platform, RedHat users may encounter some problems. I will slowly say that in addition to the above upgrades, there is also a file (/etc/rc. d/rc. sysinit) may be defective because the/proc/ksyms file is no longer available in the new kernel (kernel2.6.0). the command to open the file is as follows:
# Vi/etc/rc. d/rc. sysinit
Find:
If! LC_ALL = C grep-iq nomodules/proc/cmdline 2>/dev/null & [-f/proc/ksyms]; then
USEMODULES = y
Fi
Replace:
If! LC_ALL = C grep-iq nomodules/proc/cmdline 2>/dev/null; then
USEMODULES = y
Fi
That is, remove "& [-f/proc/ksyms]" and save the file (it is best to back up the file before the operation to avoid deletion errors. This file is the initial script of the system, (important) in this way, the kernel can load the module. of course, the iptable firewall can be started. Otherwise, the red "failed" of the firewall when it is started in the new kernel is very eye-catching. (Check whether the content in/proc/sys/kernel/modprobe in the new kernel is/sbin/modprobe. you can also manually inject the command: # echo "/sbin/modprobe">/proc/sys/kernel/modprobe ). Start to construct the new kernel.
  
   I. prepare source code
1. after downloading the tarball package, copy the kernel tarball package to the/usr/src Directory. if the package is in the current directory, run the following command:
# Cp linux-2.6.0.tar.gz/usr/src
2. go to the/usr/src directory and unbind the tarball package,
# Cd/usr/src
# Tar xvzf linux-2.6.0.tar.gz
3. if you have downloaded the patch package, install the patch. you can also run the scripts/patch-kernel script file to automatically patch the patch (prepare the patch package) or # zcat patch-2.6.0.gz | patch-p1 (I'm lazy without patching ).
  
   II. customized kernel
Customized kernel is a great learning and requires a lot of hardware knowledge, especially the 2.6.0 Kernel. if you load it from the 2.4.N configuration file, it is true that many people are in trouble. I'm re-configuring the file (X Window Server), please clear the source code tree before preparing the kernel, if you have not entered the/usr/src/linux-2.6.0 Directory, please enter this directory, the command is as follows:
# Make mrproper (this step is not required for the unlocked tarball package)
# Make gconfig (supported by the Gtk development Library)
Or make config
Or make xconfig (support from the Qt development library is required)
Note: If you are an ext3 file system, you can directly compile the support for Ext3 and Ext2 files into the kernel when customizing the kernel configuration file. otherwise, the machine will crash when you enable the new kernel. the error message is as follows: kernel panic: no init found, try passing init = option to kernel ...... or: kernel panic: VFS: Unable to mount root fs on unknown-block (0, 0). I didn't know it at first. after compiling it several times, the system always gives me a cold bench, finally, the support for Ext3 and Ext2 file systems is directly compiled into the kernel to solve this problem, and the "Module unloading" option is also selected. otherwise, you cannot uninstall the kernel module in the new kernel environment (the rmmod command cannot be used ).
  
   3. Compile the kernel and modules
After the customized kernel configuration file (/usr/src/linux-2.6.0/. config), the exciting moment is coming, compiling the kernel and the module,
# Make (this command has completed make bzImage and make modules ),
BzImage kernel files are stored in the arch/i386/boot directory. the file storage location varies depending on your CPU. I am an Intel CPU.
Note: When I was on the RedHat7.2 platform, I encountered an error message that could not be compiled. the error message is as follows:
/Tmp/cc2Hu7sH. s: 3: Error: Unknown pseudo-op: '. incbin'
Make [1]: *** [usr/initramfs_data.o] Error 1
Make: *** [usr] Error 2,
This problem can be solved only when 9.0 is reinstalled.
Note: The make command ran for 27 minutes on my 1.6 GHz M machine.
  
   IV. installation modules and kernel files
# Make modules_install install
The preceding commands can be divided into make modules_install and make install, and make modules_install to install the kernel module to/lib/modules/2.6.0. Make install to complete the mkinitrd command and kernel (bzImage) and System. for details about copying map files, see The/boot directory. the file names are different. for GRUB boot tool, the make install command has automatically modified the boot options for you and must be manually modified for LILO, rewrite the boot record.
Note: The "make modules_install install" command runs for only 30 seconds on my 1.6 GHz and M machines, which is very fast.
  
   V. postscript
The final task is to restart the system (# shutdown-r now) and check your labor results. I almost forgot one more point. it may be very important to you. after entering the new kernel, I found that the rpm command was unavailable. it turned out to be a Bug of RPM, especially for users of RH9, open the/etc/profile file and run the following command:
# Vi/etc/profile (add the following sentence at the end of the file)
If ['uname-R' = "2.6.0"]; then
Export LD_ASSUME_KERNEL = 2.2.5
Fi
That is, add a global environment variable to the system, or directly type # export LD_ASSUME_KERNEL = 2.2.5.
  
Possible problems and countermeasures when using the new kernel:
1. the new kernel cannot be started at all. Solution: reconfigure the kernel (too knowledgeable). maybe it is related to the root boot record (very few );
2. the new kernel module cannot be loaded, which may lead to many problems. for example, if the firewall cannot work, the disk cannot be mounted and the vfat and ntfs file systems cannot be mounted. the solution is as follows: upgrade module-init-tools package (I am a modutils-2.4.21-23.src.rpm package), and RedHat users may also need to modify/etc/rc. d/rc. sysinit file;
3. the RedHat user rpm command cannot be used. Solution: declare the variable in the global configuration file.
  
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.