Three methods of Centos kernel upgrade

In the work process based on the CentOS platform, it is inevitable that sometimes it is necessary to upgrade or downgrade the kernel to verify functions, debug performance, or update the entire system.

If you recompile a kernel from scratch, because the kernel features are becoming more and more complex, there are many libraries or tools that you rely on, and recompiling is time-consuming, it is particularly necessary to understand the many ways to update the kernel.

Based on the author's recent work, three methods are summarized below for your reference.

method one

If the machine is not connected to the Internet, you can download the existing kernel package to the local machine and update directly locally

  1. Download the required promulgation rpm from http://ftp.scientificlinux.org/linux/scientific/7.0/x86_64/updates/security/

  2. [ root@localhost os2]# scp [email protected]:/home/worker/kernel-3.10.0-123.1.2.el7.x86_64.rpm

[email protected]'s password:

kernel-3.10.0-123.1.2.el7.x86_64.rpm                                         100%   29MB  28.9MB/s   00:00

3.[ root@localhost os2]# yum install kernel-3.10.0-123.1.2.el7.x86_64.rpm

Loaded plugins: fastestmirror, langpacks

Examining kernel-3.10.0-123.1.2.el7.x86_64.rpm: kernel-3.10.0-123.1.2.el7.x86_64

Marking kernel-3.10.0-123.1.2.el7.x86_64.rpm to be installed

Resolving Dependencies

epel/x86_64/metalink                                                                    | 5.2 kB  00:00:00

epel/x86_64                                                                           | 4.3 kB  00:00:01

epel/x86_64/updateinfo                                                                  | 517 kB  00:00:01

epel/x86_64/primary_db                                                                  | 4.0 MB  00:02:36

....

Method Two

If the machine is connected to the Internet, directly use the package management tool to update. It should be noted that the signature mechanism is introduced in the kernel above 3.0, and the signature key needs to be imported. The reference steps are as follows:

1、 Import key
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org

Of course, if the gpgcheck=0 of the repo has been modified, it is not necessary to import the key

2、 Install elrepo's yum source

rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-2.el7.elrepo.noarch.rpm

3、 Install the kernel
In yum's ELRepo source, there is a mainline promulgated, you can install it like this:
 yum --enablerepo=elrepo-kernel install  kernel-ml-devel kernel-ml -y

Of course, you can also install long term:

yum --enablerepo=elrepo-kernel  install  kernel-lt -y

other:

http://elrepo.org/linux/kernel/el6/x86_64/RPMS/

[ root@server-mysql yum.repos.d]# yum --enablerepo=elrepo-kernel  list  |grep kernel*
Unable to read consumer identity
 * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn
abrt-addon-kerneloops.x86_64               2.0.8-6.el6                   @anaconda-RedHatEnterpriseLinux-201206132210.x86_64/6.3
dracut-kernel.noarch                       004-283.el6                   @anaconda-RedHatEnterpriseLinux-201206132210.x86_64/6.3
kernel.x86_64                              2.6.32-279.el6                @anaconda-RedHatEnterpriseLinux-201206132210.x86_64/6.3
kernel-devel.x86_64                        2.6.32-279.el6                @anaconda-RedHatEnterpriseLinux-201206132210.x86_64/6.3
kernel-firmware.noarch                     2.6.32-279.el6                @anaconda-RedHatEnterpriseLinux-201206132210.x86_64/6.3
kernel-headers.x86_64                      2.6.32-279.el6                @anaconda-RedHatEnterpriseLinux-201206132210.x86_64/6.3
libreport-plugin-kerneloops.x86_64         2.0.9-5.el6                   @anaconda-RedHatEnterpriseLinux-201206132210.x86_64/6.3
abrt-addon-kerneloops.x86_64               2.0.8-40.el6.centos           base   
dracut-kernel.noarch                       004-409.el6_8.2               updates
kernel.x86_64                              2.6.32-642.3.1.el6            updates
kernel-abi-whitelists.noarch               2.6.32-642.3.1.el6            updates
kernel-debug.x86_64                        2.6.32-642.3.1.el6            updates
kernel-debug-devel.i686                    2.6.32-642.3.1.el6            updates
kernel-debug-devel.x86_64                  2.6.32-642.3.1.el6            updates
kernel-devel.x86_64                        2.6.32-642.3.1.el6            updates
kernel-doc.noarch                          2.6.32-642.3.1.el6            updates
kernel-firmware.noarch                     2.6.32-642.3.1.el6            updates
kernel-headers.x86_64                      2.6.32-642.3.1.el6            updates

kernel-lt.x86_64                           3.10.102-1.el6.elrepo         elrepo-kernel
kernel-lt-devel.x86_64                     3.10.102-1.el6.elrepo         elrepo-kernel
kernel-lt-doc.noarch                       3.10.102-1.el6.elrepo         elrepo-kernel
kernel-lt-firmware.noarch                  3.10.102-1.el6.elrepo         elrepo-kernel
kernel-lt-headers.x86_64                   3.10.102-1.el6.elrepo         elrepo-kernel

kernel-ml.x86_64                           4.6.4-1.el6.elrepo            elrepo-kernel
kernel-ml-devel.x86_64                     4.6.4-1.el6.elrepo            elrepo-kernel
kernel-ml-doc.noarch                       4.6.4-1.el6.elrepo            elrepo-kernel
kernel-ml-firmware.noarch                  4.6.4-1.el6.elrepo            elrepo-kernel
kernel-ml-headers.x86_64                   4.6.4-1.el6.elrepo            elrepo-kernel
libreport-plugin-kerneloops.x86_64         2.0.9-32.el6.centos           base   
perf.x86_64                                4.6.4-1.el6.elrepo            elrepo-kernel

Method Three

In actual work, we often encounter the need to modify the kernel configuration, compile the driver, adjust related parameters, etc., which requires a customized kernel, and for this, a new kernel needs to be generated manually. Taking 3.10.0-123.el7 as an example, the general steps are as follows:

  1. Download the kernel first:

wget http://vault.centos.org//7.0.1406/os/Source/SPackages/kernel-3.10.0-123.el7.src.rpm

Then unzip the relevant code:

rpm2cpio kernel-3.10.0-123.el7.src.rpm |cpio -div

By default, there is a kernel header file in /usr/src, so that you can compile your own kernel module without downloading the entire kernel source code. If there is a patch that needs to be played, use the patch -p1 *.patch command Put the corresponding patch on the kernel.

  1. Update the configuration file .config

You can get the current config file of the system, or you can use the default configuration file, such as x86_64_defconfig:

cp /boot/config-3.10.0-123.el7.x86_64.config is consistent with the config produced by make oldconfig

Then use make menuconfig to configure.

  1. Compile and install

By default, the kernel and initrd will be installed under /boot, and the driver module will be installed under /lib/modules/uname -r. If you can install both in the default location, just run the following command:

make -j8;make modules; make modules_install;make install;

If you need to install to the specified path, please set the following environment variables:

export INSTALL_PATH=….

export INSTALL_MOD_PATH=

  1. Create initrd.img

initrd.img is the initialized ramdisk file, which is a memory image file. It is packaged with some of the most basic drivers and command tools, and its function is to ensure that the system can perform basic initialization and load some basic drivers, such as mounting scsi drivers, before the root partition is mounted on the system. The traditional method of making initrd is to use mkinitramfs, a system tool. Now mkinitrd will call dracut to complete the actual work. For example, the following command:

mkinitrd3.0.4 -o /boot/initrd.img-3.0.4

Then copy the generated initrd image to /boot.

  1. Update grub

In order for the boot loader to find the newly generated kernel and initrd image, grub needs to be modified. Note that if you are using grub2, you should not modify the /boot/grub2/grub.cfg file directly, but modify the grub2 configuration file. The default configuration file for grub2 is in /etc/grub2.cfg. After updating this file, you need to run the following file:

grub2-mkconfig

As for which linux mirror to start, it is determined by GRUB_DEFAULT=saved in /etc/default/grub;

It means the value used last time;

Modify kernel default startup items

grub2-set-default 0

This method needs to pay attention to the issue of kernel and module signatures. If the module signature does not pass the kernel check, it will not be loaded, which may cause the generation system to fail to start.

All in all, engineers and maintenance personnel need to flexibly choose the appropriate method to update the kernel based on the actual situation.


Change default to 0

Modify grub boot, restart###

After the installation is complete, you need to modify the Grub boot sequence to make the newly installed kernel as the default kernel.
Edit the grub.conf file,

vi /etc/grub.conf
# boot=/dev/sda
default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu
title CentOS(3.10.58)root(hd0,0)

( adsbygoogle = window.adsbygoogle || []).push({});

Recommended Posts

Three methods of Centos kernel upgrade
Centos7 upgrade kernel
CentOS7.5-1804 system kernel upgrade
CentOS6.5 upgrade kernel to 3.10.28
Centos kernel version upgrade
Linux: Centos7 upgrade the original kernel
Remember a centos 7 kernel upgrade accident
CentOS7 upgrade python3
CentOS6.X upgrade kernel Kernel
Centos6.5 openssh upgrade
centos6.9 rabbitmq 3.6.8 upgrade 3.8.2
Centos 6.4 python 2.6 upgrade to 2.7
Centos 6.4 python 2.6 upgrade to 2.7
Centos kernel compilation configuration
Graphical installation of CentOS8
Centos7 delete useless kernel
Centos delete redundant kernel
Detailed method of installing Kernel 5.x kernel version on CentOS 8 system
Centos default python2.6 upgrade to
CentOS upgrade python2 to pyth
Deployment of graphite on centos7
Centos7 silent installation of Oracle11g
Debug Kernel Panic in Centos
Implementation of CentOS8.0 Network Configuration
CentOS environment installation of Docker
centos6.5: gcc upgrade (5.2.0) process record
First understanding of the difference between centos7 and centos6 (kernel, commands, etc.)