Home>Article>Operation and Maintenance> 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/ src
and extract it to the current directory
##2. Unzip the kernel source package
#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 ./.configCopying 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"Install ncurse-devel package (make menuconfig text interface window dependency package)
[root@localhost linux-5.2.11]# yum -y install ncurses-devel
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 releaseModify the kernel name here to
5.2.11-001.el7.x86_64
File systems --->DOS/FAT/NT Filesystems --->NTFS file system support
6. Compile the kernel
[root@localhost linux-5.2.11]# make -j 4 #根据CPU核数开启多线程编译以加快编译速度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 bcAccording 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
8. Install the kernel core file
[root@localhost linux-5.2.11]# make installreboot 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 段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_64At this point, the entire kernel compilation and installation process is completed. Related references:
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!