Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Linux Kernel compilation

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

Editor to share with you a sample analysis of Linux kernel compilation, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

Download the source code

The Linux kernel is always evolving, the * kernel Kernel2.6.0 officially supports USB2.0, and one of the most significant changes in kernel module file suffixes from *. O to * .ko and so on, we can download the source code package from www.kernel.org to tarball.

Preparation in advance

As we all know, upgrade the "module-init-tools" package first, otherwise, when you install the kernel module files, you will be prompted: 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 (forcibly 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 (enter the specification file directory) # rpmbuild-bb modutils.spec (generate the binary RPM package) # cd.. / RPMS/i386 (transfer to the newly generated binary Location of the RPM package) # rpm-ivh modutils*.rpm (just generated two [modutils-2.4.21- 23.i386.rpm and modutils-debuginfo- 2.4.21.23.i386.rpm] binary RPM packages Install it together! )

Because it is on the RedHat9.0 platform, RedHat users may encounter some problems. I will say slowly that in addition to the above upgrade, there is a file (/ etc/rc.d/rc.sysinit) that 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 found: if! LC_ALL=C grep-iq nomodules / proc/cmdline 2 > / dev/null & & [- f / proc/ksyms]; replace thenUSEMODULES=yfi with: if! LC_ALL=C grep-iq nomodules / proc/cmdline 2 > / dev/null; thenUSEMODULES=yfi

That is, remove the "& & [- f / proc/ksyms]" and save the file (make a backup before the operation to avoid deletion errors, this file is the initial script of the system, it is very important), so that the kernel can load the module, of course, you can start the iptable firewall, otherwise the red "failed" when the firewall starts in the new kernel is very eye-catching. Check in the new kernel to see if the contents of / proc/sys/kernel/modprobe are: / sbin/modprobe, or manually inject instructions: # echo "/ sbin/modprobe" > / proc/sys/kernel/modprobe). Let's start building a new kernel.

Prepare the source code

1. After downloading to the tarball package, copy the kernel tarball package to the / usr/src directory. Assuming that the package is in the current directory, run the following command:

# cp linux-2.6.0.tar.gz / usr/src

2. Change to the / usr/src directory and unlock the tarball package.

# cd / usr/src#tar xvzf linux-2.6.0.tar.gz

3. If you also downloaded the patch pack, put the patch on, or you can run the scripts/patch-kernel script file to automatically patch (ready for the fix pack) or # zcat patch-2.6.0.gz | patch- p1.

Second, customize the kernel

Customizing the kernel is a great knowledge, which requires a lot of hardware knowledge, especially the 2.6.0 kernel. If you load it from the 2.4.N configuration file, indeed, a lot of people have had trouble. I am reconfiguring the file (X window server). Please clean the source code tree before configuring the kernel. If you have not entered the / usr/src/linux-2.6.0 directory, please enter this directory with the command as follows:

# make mrproper (this step is not required for the newly unpacked tarball package) # make gconfig (requires support from the Gtk development library) or make config or make xconfig (requires support from the Qt development library)

Note: if you are an ext3 file system, compile the support for Ext3 and Ext2 files directly into the kernel when you customize the kernel configuration file, otherwise, the machine will pawn when you enable the new kernel. The error message is as follows: kernel panic: no init found, try passing init = kernel. Or: kernel panic:VFS:Unable to mount root fs on unknown-block (0J0), I don't know at first, compiled several times, the system always benched me, * compile the support for Ext3 and Ext2 file systems directly into the kernel to solve this problem, and select the "Module unloading" option, otherwise, you can't unmount kernel modules in the new kernel environment (the rmmod command is not available).

Compiling kernels and modules

After the customized kernel configuration file (/ usr/src/linux- 2.6.0/.config), the exciting time has come to compile the kernel and modules, # make (this command has finished the work of make bzImage and make modules), bzImage kernel files are in the arch/i386/boot directory, and different kernel files of your CPU are stored in different locations. I am the CPU of Intel.

Note: when I was on the RedHat7.2 platform, I had 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 1make: * [usr] Error 2

Reinstalled a 9.0 to solve this problem. Description: the make command ran on my 1.6GHz 128MB machine for a full 27 minutes.

Fourth, install modules and kernel files

# make modules_install install

The above command can be broken down into make modules_install and make install,make modules_install to install kernel modules under / lib/modules/2.6.0. Make install completes the mkinitrd command and the copy of the kernel (bzImage) and System.map, please check the / boot directory, the file name is different, such as GRUB boot, make install command has helped you automatically modify the boot options, for LILO to manually modify, rewrite boot record.

Explanation: the make modules_install install command only ran for more than 30 seconds on my 1.6GHz 128m machine, very fast.

5. Postscript

The job of * is to restart the system (# shutdown-r now) and check the fruits of your labor. I almost forgot another point, which may be very important to you. After entering the new kernel, I found that the rpm command could not be used. It turns out that this is a Bug of RPM. Especially for RH9 users, please open the / etc/profile file as follows:

# vi / etc/profile (add the following at the end of the file) if [`uname-r` = "2.6.0"]; thenexport LD_ASSUME_KERNEL=2.2.5 fi

That is, add a global environment variable to the system, or you can type # export LD_ASSUME_KERNEL=2.2.5 directly.

Possible problems and countermeasures in using the new kernel:

1, the new kernel can not get up at all, the solution: reconfigure the kernel (knowledgeable), maybe it has something to do with the root boot record (less).

2. The new kernel module cannot be loaded, which will lead to many problems, such as the firewall can not work, mount does not play CD and vfat and ntfs file system, the solution: upgrade the module- init-tools package (I am the modutils-2.4.21- 23.src.rpm package), RedHat users may also have to modify the / etc/rc.d/rc.sysinit file.

3, RedHat user rpm command can not be used, the solution: please declare the variables in the global configuration file.

The above is all the contents of the article "sample Analysis of Linux Kernel compilation". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report