Compiling the Linux kernel is the basic function of kernel development, and if we add kernel functionality by directly modifying the Linux kernel code, the modified kernel code must be recompiled to generate a new image file and then load the image file to enable the new kernel.
The kernel compilation process differs for different Linux distributions. The platform used here is Fedora 10,linux kernel is 2.6.27.5, the Linux kernel to be compiled is 2.6.27.39. This is simply compiling a clean kernel and loading it successfully without modifying the kernel.
The first step: Download the kernel
In general, the version of the kernel to be compiled (that is, the new kernel) is not lower than the running version, and if there is a large gap between the two versions, you may need to update the compilation tools such as Gcc,binutils. This is only compiled using the kernel version of the Linux distribution, so that all kernel compilation tools are available and need not be updated.
1), first look at the current environment of the kernel version number
#uname –r
2.6.27.5-117.fc10.i686
2), download the corresponding core compression package
URL: http://www.kernel.org/pub/linux/kernel/v2.6/(the author selected is 2.6.27.39.tar.bz2). Copy the kernel compression package to a directory under Linux, such as/USR/SRC.
The author is in the XP system to download the package first, and then copy it to the Linux directory. This does not directly copy the compressed package to the Linux/usr/src directory, only to copy it to the Linux desktop, and then use the CP command to copy the compressed package to the Linux/usr/src directory.
3), decompression package generation code Tree/usr/src/linux-2.6.27.39
Instructions are as follows:
#cd/USR/SRC
#tar JXVF linux-2.6.27.39.tar.bz2
#cd linux-2.6.27.39
Note: If the selected compression package suffix is. GZ, the JXVF in the second instruction in the (3) should be replaced by ZXVF.
Step two: Build the kernel configuration file. config
The Linux kernel code is so large that it is used in many architectures and contains a large number of drivers. When the kernel is built, it is configured according to the actual situation, and all configurations are saved in a configuration file named. config in the top-level directory of the kernel code tree.
1), copy the configuration file template
The configuration file can be generated from scratch, which is generally not necessary because the currently running kernel already has a corresponding configuration file in the/boot directory. Copy the template to the/usr/src/linux-2.6.27.39 directory:
#make Mrproper
#cp/boot/config-' uname–r './.config
The command "Make Mrproper" is used to ensure that the kernel tree is clean, and if the kernel tree has already been compiled, the command is valid, and if the kernel tree is compiled for the first time, you can omit the command. Command "cp/boot/config-' Uname–r './.config" "" Uname–r "represents 2.6.27.5-117.fc10.i686,"./.config "The previous point indicates that the copy is placed at the beginning of the default directory (that is,/ usr/src/linux-2.6.27.39), and name it as a hidden file of. config.
2. config profile to generate a new kernel
Although the template is available after the copy, the configuration of the. config file does not necessarily include all the compilation options for the new kernel, you can use the following command:
#make Oldconfig or #make silentoldconfig
The command "#make Oldconfig" reads the. config file and updates it according to the new kernel version. This command outputs all of the configuration values for the new kernel, the output setting value if the configuration item is set in. config, and the program pauses the user input setting value if it is a new item. The command "#make silentoldconfig" and the command "#make oldconfig" feature are similar, but he does not output information unless the new option requires user input.
By this, the generated. config file is ready for use.
Step three: Compile and install a new kernel
1), you can define your own version number of the kernel
Before compiling the kernel, users can define their own kernel version number, which is intended for easy identification. There is a file makefile in the root directory of the kernel code tree, and the value in the last line of "extraversion=.39" in the first 4 lines of the line. 39 can be modified. (You can certainly not do anything with the makefile file)
2), compiling the new kernel
Execute the following three commands:
#make All
#make Modules_install
#make Install
The command "Make all" is used to generate the desired kernel image and module, and the "Making Modules_install" will install the module under "default directory/lib/module/< kernel version number >"; Finally, several files, such as kernel images, are copied to the "/boot" directory, and the bootstrapper configuration is modified to enable the new kernel. These three commands must be executed successfully.
Description: For dual-core processors, the command "make all" can be used to speed up by using "make-j2 all" instead.
3), you can modify the boot program grub
If all three of these commands are successful, the user can observe the profile/boot/grub/menu.lst of the bootstrapper grub and modify the configuration appropriately. One way to open menu.lst is:
#gedit/boot/grub/menu.lst
Description: 1, the command "Gedit/boot/grub/menu.lst" only use Gedit to open the configuration file Menu.lst, others can also use eamcs,vim,cat,tail and so on.
2, in order to be able to directly operate the menu, you can menu.lst file in the Hiddenmenu Line commented out (ex-plus #) or deleted, and can be set according to the needs of the default and timeout values, respectively, indicating the defaults and wait time.
4), restart view
Using the command #reboot reboot the system to see that the Grub menu already contains the newly compiled kernel.