After compiling kernel, it is considered as a beginner Linux! I tried it many times before, but it was an inexplicable mistake. Today I am tossing it over again. I finally saw CC, LD ....
Compiling the Linux kernel is the basic function of kernel development. If we directly modify the Linux kernel code to add the kernel function, the modified kernel code must be re-compiled to generate a new image file, then, load the image file to enable the new kernel.
The kernel compilation process varies with Linux releases. The platform used here is ubutun9.10 Linux kernel 2.6.31-23-generic, and the Linux kernel to be compiled is 2.6.36.4. Here, we only compile a clean kernel and load it successfully without modifying the kernel.
Step 1: Download the kernel
Generally, the version of the kernel to be compiled (that is, the new kernel) cannot be earlier than the running version. If there is a large gap between the two versions, it may need to be updated, such as GCC, binutils and other compilation tools. Only the kernel version corresponding to the Linux release version is used for compilation, so that all kernel compilation tools are ready-made and do not need to be updated.
1) Check the kernel version number in the current environment.
# Uname-R
2.6.31-23-generic
2) download the corresponding kernel package
URL: http://www.kernel.org/(pen choice is linux-2.6.36.4.tar.bz2, only 67.0 MB, initially suspected wrong, how so small> _ <, decompress 376.4 MB ). Copy the compressed kernel package to a directory in Linux, such as/usr/src.
3) decompress the package to generate the code tree/usr/src/linux-2.6.36.4
Command: root @ yuebao-desktop :~ # Tar jxvf/home/yuebao/downloads/linux-2.6.36.4.tar.bz2-C/usr/src/
# Linux-2.6.36.4/CD/usr/src/
Note:
1. Switch to root from here, and all subsequent compilation will be performed under root.
2.if the selected compressed package is suffixed with .gz, 3) the jxvf in the Second instruction should be replaced with zxvf.
Step 2: generate the Kernel configuration file. config
The Linux kernel code is very large and used in many architectures, including a large number of drivers. You need to configure the kernel according to the actual situation when generating the kernel. All the configurations will be saved in a configuration file named. config under the top-level directory of the kernel code tree.
1) copy the configuration file template
The configuration file can be generated from the beginning. Generally, this is not necessary because the currently running kernel already has a corresponding configuration file under the/boot directory. Copy the template to the/usr/src/linux-2.6.36.4 directory:
# Make mrproper
# Cp/boot/config-'uname-R'./. config
The "make mrproper" command is used to ensure that the kernel tree is clean. If the kernel tree has been compiled, this command is valid. If the kernel tree is compiled for the first time, this command can be omitted. Command "CP/boot/config-'uname-R '. /. in config, "'uname-R'" indicates 2.6.31-23-generic, ". /. the first point in config is to place the copy in the default directory (I .e./usr/src/linux-2.6.36.4) that begins with and name it. the hidden file of config.
2) generate the. config configuration file for the new kernel
Although the template is available after the copy, the configuration of the. config file does not necessarily include all the compilation options of the new kernel. You can use the following command:
# Make oldconfig or # Make silentoldconfig
Command "# Make oldconfig" to read the. config file and update it according to the new kernel version. Specifically: This command outputs all the configuration values of the new kernel. if there are settings in config, the set value is input. If it is a new item, the program will suspend the user to enter the set value. If you do not know how to configure it, you can enter all the way until the end, using the default configuration. The command "# Make silentoldconfig" is similar to the command "# Make oldconfig", but does not output information unless it is required by the new option.
At this point, you can use the regenerated. config file.
Step 3: Compile and install the new kernel
1) You can define your own kernel version.
Before compiling the kernel, you can define your own kernel version number to facilitate identification. There is a file makefile under the root directory of the kernel code tree. The value of. 4 in the last line of "extraversion =. 4" of the first 4 lines can be modified. (Of course, you can not process the MAKEFILE file)
2) Compile the new kernel
Run the following three commands:
# Make all
# Make modules_install
# Make install
The "make all" command is used to generate the desired kernel image and module;
"Make modules_install" will install the module under "/lib/modules/<version number of the kernel to be compiled>" (local file system, not/usr/src/linux-2.6.36.4, in this directory, the symbolic link build will be built to your kernel source directory, my build->/usr/src/linux-2.6.36.4, one of the role is to write your module makefile, will be used, such as the makefile of helloworld, you can write it like this
Kerneldir? =/Lib/modules/2.6.36.4/build without directly specifying/usr/src/linux-2.6.36.4. In addition, you will see the modules of other kernel versions in the "/lib/modules" folder, including the current system environment. Do not delete these folders;
"Make install" Eventually copies the kernel image and other files to the "/Boot" directory, and copies the "arch/x86/boot/bzimage" file in the compilation folder to "/Boot ", at the same time, the config and system. the map file will eventually contain the following three files in "/Boot:
/Boot/config-2.6.36.4
/Boot/system. Map-2.6.36.4
/Boot/vmlinuz-2.6.36.4.
Is an initrd. IMG file missing (initial RAM disk file )? Run the following command to create one:
$ Mkinitramfs 2.6.36.4-O/boot/initrd. img-2.6.36.4
Note: For dual-core processors, use the "make all" command instead of "make-J2 all" to speed up the process.
3) You can modify the boot program grub.
If the preceding three commands are successfully executed, you can observe the grub configuration file/boot/GRUB/menu. LST of the boot program and modify the configuration reasonably. One of the methods to Open menu. lst is:
# Gedit/boot/GRUB/menu. lst
Note: 1. the command "gedit/boot/GRUB/menu. lst" only uses gedit to open the configuration file menu. lst. You can also use eamcs, Vim, cat, and tail.
2. In order to operate the menu directly in the future, you can set menu. in the LST file, comment out the line "hiddenmenu" (prefix #) "or delete it. You can set the default and timeout values as needed, indicating the default start item and wait time respectively.
If you do not want to modify the grub boot menu (not sure about the new kernel), you can manually specify the new kernel when starting Linux as follows:
Restart the computer, Press ESC on the GRUB menu interface (if you do not see it, then restart the computer), press "c" to enter the command mode, and set the partition of the Startup File first, suppose "/Boot" is in the first partition of the first hard disk. If it is in another partition, change the number "1" below to "2, 3, 5, 6, 7 ......" And so on:
Set root = (hd0, 1)
Specify the kernel image and virtual RAM disk file location:
Linux/boot/vmlinuz-2.6.36.4 root =/dev/sda1
Initrd/boot/initrd. img-2.6.36.4
Note: In grub command mode, you can press the "tab" key to automatically complete the task. Do not enter one word or more. Finally, enter "Boot" to start.
4) Restart to view
Run the command # reboot to restart the system. You can see that the GRUB menu contains the newly compiled