1. Prepare the source code.
The latest source code can be obtained from kernel.org, such as the current latest version of 2.6.31: $ wget linux-kernel/v2.6/linux-2.6.31.tar.bz2 "> http://oss.ustc.edu.cn/linux-kernel/v2.6/linux-2.6.31.tar.bz2
2. decompress the source code:
$ Tar xvf linux-2.6.31.tar.bz2-C/usr/src/TIP: Of course, it is not necessary to extract to/usr/src/, you can extract to any location.
3. Check the source code. This step is not required ):
$ Cd/usr/src/linux-2.6.31
$ Make mrproper
TIP: This step is used to check whether the source code contains. o files and dependencies. This step is not required during source code compilation. Make mrproper is used to clear environment variables and configuration files.
4. Compile the kernel
By default, the compiled and output files are stored in the source code directory. You can use the O = output/dir parameter to specify the output file location where the letter O is not a number 0 ). Many people who compile the kernel for the first time will encounter a problem. The space in the partition where/usr is located is not enough. In this case, this parameter is very useful.
The source code provides a lot of configuration methods, it is recommended to use menuconfig: Enter/usr/src/linux-2.6.31, has been entered is skipped: $ cd/usr/src/linux-2.6.31
Create/build/kernel menuconfig Folder: $ mkdir-p/home/your username/build/kernel menuconfig
Use menuconfig to configure: $ make O =/home/your username/build/kernel menuconfig
For the first time to compile the kernel, it is not recommended to start directly from the default Kernel configuration, it is recommended to use the release version of the built-in configuration file, usually/boot there will be a config-2.6.xx file. Select Load an Alternate Configuration File, enter the name of the config File under/boot, and Load the File. For the first compilation, it is best not to modify the configuration at will. If the configuration fails, it will leave a mental shadow :-) in the configuration, you can modify the configuration according to your own needs, don't change anything you don't understand. Do not forget to save the file after it is finished. Fill in. config as the file name is saved.
Next, we will start the official compilation. Compilation may take some time. To avoid unexpected shutdown of the terminal, you can use screen. The specific usage will not be discussed here.
$ Make O =/home/name/build/kernel
To speed up compilation, you can use the-j parameter to enable multithreading. For example, a dual-core cpu can be compiled in this way.
$ Make-j4 O =/home/name/build/kernel
Generally, the n value of-jn is twice the number of cores.
5. Install the kernel
$ Sudo make O =/home/name/build/kernel modules_install install
6. Generate initrd
$ Sudo mkinitramfs-o/boot/initrd-img.2.6.31 2.6.31 for other mkinitramfs parameters, refer to man mkinitramfs. For more information about the role of initrd, search for it by google. I will also write an article to analyze initrd recently.
7. Modify Guide
Grub can be used directly:
$ Sudo update-grub
You can also edit the/boot/grub/menu. lst or/boot/grub. cfg file by yourself.
8. Restart
After the restart, run the following command to check whether the compiled kernel is used:
$ Uname-