How to compile the kernel in CentOS 6.5
Preface
Linux Kernel is the core of the operating system and the most basic part of the operating system.
The volume structure of the Linux kernel is single-core, but it fully adopts the design idea of micro-kernel, so that although it is single-core, it works in a modular mode, and this module can be dynamically loaded. or uninstall; linux manages system processes, memory, device drivers, files, and network systems, and determines system performance and stability. If we want to customize a more efficient and stable kernel based on our own needs on the basis of understanding the Linux kernel, we need to manually compile and configure the relevant parameters and information in the kernel.
Note: If the two kernel modules are of different versions, they cannot be used across versions.
Body
First of all, we want to get the Linux kernel compressed file, get a lot of paths, the most direct is to get the kernel official website (http://www.kernel.org ), you can also download images from different image sites.
Note:/usr/src. In general, the source code is usually put in this path when we make the linux kernel, and there is a link called linux or something, so we should put it in this path when we expand it.
Download a kernel of 3.13.2 and specify an expansion path when expanding. The file size is large, more than 70 MB, and may take some time.
# Tar linux-3.13.2.tar.xz-C/usr/src/
Expand and you will see the file that generates a linux-3.13.2 in the/usr/src/directory.
For future convenience, we will create a link for him:
# Ln-sv linux-3.13.2 linux
Let's take a look at the files in cd to the linux directory:
# Cd/usr/src/linux
I will not describe the contents here. If you are interested, you can check them out.
The next step is to configure the kernel. There are many Kernel configuration methods in this step, and each make method is one. We can only select one method:
Make config: traverse and select the kernel features to be compiled
Make allyesconfig: configure all compilable kernel features
Make allnoconfig: not all files are not compiled, but all the files that can be selected are answered as NO and only required are selected as yes.
Make menuconfig: in this case, open a file window and select the menu. The window to be opened by this command must be larger than 80 characters in width. After opening it, you can select the items to be compiled.
The following two items can be selected with the mouse:
Make kconfig (in the KDE Desktop Environment, and the qt development environment is installed)
Make gconfig (Gnome desktop environment and install gtk Development Environment)
Menuconfig: if you use this command, you need to install gcc and ncurses-devel for the newly installed system to open the package, and then select the package. This method is also used for comparison. multiple:
If you do not want to use other methods, copy the/boot/config-version-platform on the current system to/usr/src/linux /. config overwrites this file, and then changes the configuration information; you can retain what you need, delete what you don't need, and add any new ones. This is configured as needed;
Note: if the compilation is on a remote connection, make will have problems. If the remote connection is disconnected, the running processes are also disconnected. The make process must be running on the current system. sub-processes, some of which will no longer exist once the parent process crashes, as the saying goes: this is the truth;
Therefore, we use the screen command to perform operations. If we do not install the screen, we can start n virtual desktops in a window. Even if we quit, the previous content will be retained, switch to screen to see the screen icon on the title bar of the window:
# Screen-ls: You can view how many screens are currently enabled
Press Ctrl + a and press d to hide the screen desktop.
It takes a long time to compile the kernel, so we can compile on screen and then hide the screen desktop;
Re-access screen:
# Screen-r: keep up with screenID.
Then let's start compiling. (I spent about two hours compiling here. I didn't specify the number of cpu Cores during make. By default, I used a single core for compilation, so it took a long time)
# Make
After compilation, we can proceed to the next step:
# Make modules_install
After this step, you can check that a file module named after the version number is generated in the/lib/modules/directory.
Go down and run the command after modules.
# Make install
After the installation, a kernel file vmlinuz-3.13.2 will be generated under the/boot/directory, there are a few files that are the same as your current compiled version, you can look at the ls:
# Ls/boot/
If there is no problem, we should have compiled a new kernel here. You can check it in the grub. conf configuration file:
# Vim/boot/grub. conf
Okay. Let's take a look at the restart, OK, and restart! If it succeeds, you can go to the kernel selection interface. The new kernel we compile will be OK. Well, it will be over!
To sum up our installation steps:
1. Obtain the kernel source code and decompress it to/usr/src.
# Tar xf linux-3.13.5.tar.xz-C/usr/src
# Ln-sv/usr/src/linux-3.13.5/usr/src/linux
2. Configure the kernel features (select a method)
Make config: traverse and select the kernel features to be compiled
Make allyesconfig: configure all compilable kernel features
Make allnoconfig: not all are not compiled.
Make menuconfig: open a file window and select a menu.
Make kconfig (in the KDE Desktop Environment, and the qt development environment is installed)
Make gconfig (Gnome desktop environment and install gtk Development Environment)
3. Compile the kernel
# Make [-j #]: # It can be up to twice the total number of CPU physical cores.
4. Install the kernel module
# Make modules_install
5. Install the kernel
# Make install
6. Verify and Test
# Cat/boot/grub. conf
Check whether the new kernel has been added, restart the system, and test
End:
In fact, it seems that it is not very difficult to compile a new kernel. It is similar to the httpd step we used to compile the source code, that is, the first step is troublesome, And it is okay to be careful, of course, if there is anything wrong with it, I would like to mention more in different princes!