How to compile and install a new version of the kernel from source code under CentOS

WJ
Release: 2020-06-06 17:14:27
Original
2375 people have browsed it

How to compile and install a new version of the kernel from source code under CentOS

How to compile and install a new version of the kernel from source code under CentOS?

At work, many times due to the need to use new technical solutions, a newer version of the kernel is needed to support new functions, and the kernel version that comes with the CentOS system is generally older, so we The system kernel needs to be upgraded and a new version of the kernel needs to be installed. Here, taking the CentOS 7 system as an example, the process of compiling and installing the latest version of the kernel is summarized as follows:

1. Download the latest stable version of the kernel source code package to/usr/local/ srcand extract it to the current directory

How to compile and install a new version of the kernel from source code under CentOS

##2. Unzip the kernel source package

How to compile and install a new version of the kernel from source code under CentOS

#3. Copy the existing version of the kernel compilation config configuration file from the /boot directory to the new kernel source code decompression directory and rename it For the hidden file of .config

[root@localhost src]# cd linux-5.2.11 [root@localhost linux-5.2.11]# cp /boot/config-3.10.0-957.el7.x86_64 ./.config
Copy after login

Copying the original kernel config file from the boot directory is mainly for convenience. This file saves the module configuration information installed by the kernel when installing the system (otherwise it needs to be reinstalled Manually specify the compilation configuration for each module).

4. Install dependency packages

Install development tool package group

[root@localhost linux-5.2.11]# yum -y groupinstall "development tools"
Copy after login

Install ncurse-devel package (make menuconfig text interface window dependency package)

[root@localhost linux-5.2.11]# yum -y install ncurses-devel
Copy after login

5. Run make menuconfig and open the compilation options menu window of the text interface. You can adjust the module compilation options loaded by the kernel, such as modifying the compiled kernel name and adding new modules that were missing from the previous system. wait.

Modify the kernel name:

General setup --->local version -append to kernel release
Copy after login

Modify the kernel name here to

5.2.11-001.el7.x86_64

How to compile and install a new version of the kernel from source code under CentOS

Newly added NTFS file system support module:

File systems --->DOS/FAT/NT Filesystems --->NTFS file system support

How to compile and install a new version of the kernel from source code under CentOS

It is recommended to compile in module mode (M option). (The * sign is statically compiled and packaged into the kernel file. If there are more newly added modules, the size of the kernel file will increase)

6. Compile the kernel

[root@localhost linux-5.2.11]# make -j 4 #根据CPU核数开启多线程编译以加快编译速度
Copy after login

How to compile and install a new version of the kernel from source code under CentOS

Start the long compilation process, which will take about 1-2 hours, depending on the performance of the CPU hardware.

If an error is prompted at the beginning of compilation, you may need to install the corresponding component package in advance, for example:

[root@localhost linux-5.2.11]# yum -y install openssh-devel elfutils-libelf-devel bc
Copy after login

According to the corresponding error prompt, install the corresponding component package in yum mode, and some component packages are in epel source, so the epel source warehouse needs to be configured in advance.

7. Compile and install the module

After the compilation is completed, execute make modules_install to install the kernel module

[root@localhost linux-5.2.11]# make modules_install
Copy after login

8. Install the kernel core file

[root@localhost linux-5.2.11]# make install
Copy after login

reboot

If you need to set the new version of the kernel as the default startup kernel, you can use this command

grub2-set-default 0 #0表示 /boot/grub2/grub.cfg 文件中排在第一位的 menuentry 段
Copy after login

After restarting the system, check the kernel version. It is the latest version 5.2.11

[root@localhost ~]# uname -r 5.2.11-001.el7.x86_64
Copy after login

At this point, the entire kernel compilation and installation process is completed.

Related references:

centOS tutorial

The above is the detailed content of How to compile and install a new version of the kernel from source code under CentOS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!