docker, upgrade the linux kernel

This article is from the " Storage Kitchen " blog, please be sure to keep this source http://xiamachao.blog.51cto.com/10580956/1755354

 

Since docker needs to be installed for learning recently, it is necessary to upgrade the CentOS kernel to 3.8 or above! 

 

In the process of working on the CentOS platform, it is inevitable that sometimes the kernel needs to be upgraded or downgraded 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 dependent libraries or tools, and the recompilation is time-consuming, it is particularly necessary to understand the various ways to update the kernel.

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

 

method one

If the machine cannot be connected to the Internet, you can download the existing kernel package to the local machine and update it 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

--> Running transaction check

---> Package kernel.x86_64 0:3.10.0-123.1.2.el7 will be installed

--> Finished Dependency Resolution

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 already connected to the Internet, you can directly use the package management tool to update it. It should be noted that the signature mechanism is now 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 you have modified the gpgcheck=0 of the repo, you can also not import the key


2. Install the yum source of elrepo

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

 

3. Install the kernel
In the ELRepo source of yum, there is a mainline promulgation, 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/

 

copy code
[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
copy code

 

 

 

 

Method three

In actual work, it is often necessary to modify the kernel configuration, compile the driver, adjust the relevant parameters, etc., which requires a customized kernel, and a new kernel needs to be manually generated for this purpose. 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.



2. 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 the same as the config produced by make oldconfig

Then use make menuconfig to configure.



3. 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=



4. Create initrd.img

initrd.img is the initialized ramdisk file, which is a memory image file. It is a package of some basic drivers and command tools. Its function is to ensure that the system can perform basic initialization and load some basic drivers, such as mounting scsi drivers, before the system has mounted the root partition. 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 does:



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

Then copy the generated initrd image to /boot.



5. Update grub

In order for the boot loader to find the newly generated kernel and initrd images, 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 /etc/grub2.cfg. After updating this file, you need to run the following file:

grub2-mkconfig

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

It means the last used value;

Modify the kernel default startup items

grub2-set-default 0



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



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

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326360330&siteId=291194637