Compile the 3.0.4 kernel in Ubuntu
The Linux kernel version 3.0 has been released for some time. I don't know whether the kernel of this version is easy to use. At present, Linux of each release version still does not use the 3.0 kernel, so you can compile the kernel yourself to feel it! This opportunity to compile the kernel allows you to familiarize yourself with the kernel compilation steps.
1. Download and decompress the kernel to any directory
Download the latest kernel source code 3.0.4 from the official website of the source code. You can decompress the package to any directory. Put it in the main directory:
1 |
~$ tar xjvf linux-3.0.4.tar.bz2 |
2. Configure the kernel
The kernel is configured to obtain the Kernel configuration file. config. By configuring the kernel, you can increase or decrease the support for some kernel features for the kernel that is successfully compiled in the future. There are multiple methods to configure the kernel, including text-based configuration methods and graphical user interfaces. The following uses the make menuconfig method that is widely used:
1 |
~/linux-3.0.4$sudo apt-get install libncurses5-dev |
2 |
~/linux-3.0.4$sudo make menuconfig |
Because the configuration method is based on the ncurses library, you must install the ncurses library before starting the configuration interface. Before starting the configuration interface, you must enter the source code root directory. After the configuration interface is started successfully, see:
The kernel is compiled according to the default configuration method. Therefore, you can exit and save the configuration menu after it is started. The. config file is generated under the root directory of the kernel source code.
3. Compile
Compiling the kernel includes two parts: one is to compile the kernel, that is, the part marked as Y in the compilation configuration option, which eventually forms the bziamge image file; the other is to compile the kernel module, that is, the part of the kernel marked as m in the compilation configuration option. the target file of the kernel module ending with Ko.
The compilation of the above two parts can be completed in sequence through make bzimage and make modules, or directly through a make command. The entire process of compiling the kernel is long. Therefore, you can add the-J parameter to make to improve the compilation efficiency. Using this option in make will allocate n concurrent tasks to the compilation process, which can shorten the Compilation Time. N is twice the number of CPUs.
1 |
~/linux-3.0.4$sudo make -j4 |
4. Installation
The installation process is divided into two parts. First, install the kernel module. This process copies the kernel module generated when the kernel module is compiled to the/lib/modules/3.0.4/directory, 3.0.4 indicates the corresponding kernel version. The command used is as follows:
1 |
~/linux-3.0.4$sudo make modules_install |
Run the following command to install the compiled kernel:
1 |
~/linux-3.0.4$sudo make install |
The kernel installation process mainly completes the following tasks:
1. Copy the kernel image bzimage generated during kernel compilation to the/boot directory and name it vmlinuz-3.0.4. If you use an x86 CPU, the image is located in the arch/x86/boot/directory (under the kernel source code being compiled ).
2. Change ~ Copy System. Map under the/linux-3.0.4/directory to the/boot/directory and rename it system. Map-3.0.4. This file contains the symbol table of the kernel.
3. Change ~ The. config under the/linux-3.0.4/directory is copied to the/boot/directory and renamed as a config-3.0.4.
5. Create the initrd. imgfile
Initrd. IMG is the initial ramdisk file. It is an image file that packs some basic drivers and command tools into the image file. This image file is used to release the initrd file to the memory before the system has mounted the root partition, as a virtual root partition, execute related scripts and run the insmod command to load the required modules.
The specific creation method is as follows:
1 |
~/linux-3.0.4$sudo mkinitramfs 3.0.4 -o /boot/initrd.img-3.0.4 |
6. Update grub
The last step is to update the grub Startup menu. You can use the following command to automatically update the Startup Menu:
In this way, the compiled kernel is placed first in the Startup menu. If you need to modify the default system startup sequence in the Startup menu, modify/boot/GRUB/grub. set default = In the cfg file.
OK. The kernel has been compiled.