1, view the current kernel version
$ uname -r 3.10.0-514.el7.x86_64 $ uname -a Linux k8s-master 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux $ cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core)
2, upgrade the kernel
Yum update source warehouse
$ yum -y update
Enable ELRepo warehouse
ELRepo warehouse is based on Linux for enterprise-class storage, delivery and other community support for RedHat Enterprise (RHEL) RHEL based Linux distributions (CentOS, Scientific, Fedora, etc.).
ELRepo focused on packages and associated hardware, including file system drivers, video drivers, network drivers, sound drivers and the camera driver and the like.
# Import public key ELRepo warehouse
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# Yum install ELRepo warehouse source
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
3, view the available system kernel package
We can see both versions 4.4 and 4.18
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn elrepo-kernel | 2.9 kB 00:00:00 elrepo-kernel/primary_db | 1.8 MB 00:00:03 Available Packages kernel-lt.x86_64 4.4.155-1.el7.elrepo elrepo-kernel kernel-lt-devel.x86_64 4.4.155-1.el7.elrepo elrepo-kernel kernel-lt-doc.noarch 4.4.155-1.el7.elrepo elrepo-kernel kernel-lt-headers.x86_64 4.4.155-1.el7.elrepo elrepo-kernel kernel-lt-tools.x86_64 4.4.155-1.el7.elrepo elrepo-kernel kernel-lt-tools-libs.x86_64 4.4.155-1.el7.elrepo elrepo-kernel kernel-lt-tools-libs-devel.x86_64 4.4.155-1.el7.elrepo elrepo-kernel kernel-ml.x86_64 4.18.7-1.el7.elrepo elrepo-kernel kernel-ml-devel.x86_64 4.18.7-1.el7.elrepo elrepo-kernel kernel-ml-doc.noarch 4.18.7-1.el7.elrepo elrepo-kernel kernel-ml-headers.x86_64 4.18.7-1.el7.elrepo elrepo-kernel kernel-ml-tools.x86_64 4.18.7-1.el7.elrepo elrepo-kernel kernel-ml-tools-libs.x86_64 4.18.7-1.el7.elrepo elrepo-kernel kernel-ml-tools-libs-devel.x86_64 4.18.7-1.el7.elrepo elrepo-kernel perf.x86_64 4.18.7-1.el7.elrepo elrepo-kernel python-perf.x86_64 4.18.7-1.el7.elrepo elrepo-
4, install the latest version of the kernel
$ yum --enablerepo=elrepo-kernel install kernel-ml
--enablerepo
Options open designated warehouse on CentOS systems. Is enabled by default elrepo
, here elrepo-kernel
replaced.
5, set grub2
After a good kernel is installed, you need to take after the default boot option and restart to take effect
View all available cores on the system:
$ sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg 0 : CentOS Linux (4.18.7-1.el7.elrepo.x86_64) 7 (Core) 1 : CentOS Linux (3.10.0-862.11.6.el7.x86_64) 7 (Core) 2 : CentOS Linux (3.10.0-514.el7.x86_64) 7 (Core) 3 : CentOS Linux (0-rescue-063ec330caa04d4baae54c6902c62e54) 7 (Core)
Setting new kernel as the default version of grub2
There are four cores on the server, we want to use this version 4.18, you can grub2-set-default 0
command or edit /etc/default/grub
to set the file
1, the grub2-set-default 0
command sets
Where 0 is check out the available cores above
grub2-set-default 0
Method 2, editing /etc/default/grub
files
Provided GRUB_DEFAULT = 0, the number displayed by the above query as the core 0 is the default kernel:
$ vim /etc/default/grub GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=0 GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rhgb quiet" GRUB_DISABLE_RECOVERY="true"
Generate grub configuration file and restart
$ grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-4.18.7-1.el7.elrepo.x86_64 Found initrd image: /boot/initramfs-4.18.7-1.el7.elrepo.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-862.11.6.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-862.11.6.el7.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-063ec330caa04d4baae54c6902c62e54 Found initrd image: /boot/initramfs-0-rescue-063ec330caa04d4baae54c6902c62e54.img done
$reboot
6. Verify
$ uname -r 4.18.7-1.el7.elrepo.x86_64
7, delete the old kernel (optional)
View all system kernel:
$ rpm -qa | grep kernel kernel-3.10.0-514.el7.x86_64 kernel-ml-4.18.7-1.el7.elrepo.x86_64 kernel-tools-libs-3.10.0-862.11.6.el7.x86_64 kernel-tools-3.10.0-862.11.6.el7.x86_64 kernel-3.10.0-862.11.6.el7.x86_64
Method 1, yum remove delete the old kernel RPM package
$ yum remove kernel-3.10.0-514.el7.x86_64 \
kernel-tools-libs-3.10.0-862.11.6.el7.x86_64 \
kernel-tools-3.10.0-862.11.6.el7.x86_64 \
kernel-3.10.0-862.11.6.el7.x86_64
方法2、yum-utils
tool
If you install a kernel no more than three, yum-utils
the tool does not remove any of them. Only when you install kernel is greater than three, it will automatically delete old kernel.
Install yum-utils
$ yum install yum-utils
Remove the old version
package-cleanup --oldkernels
1, view the current kernel version
$ uname -r 3.10.0-514.el7.x86_64 $ uname -a Linux k8s-master 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux $ cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core)
2, upgrade the kernel
Yum update source warehouse
$ yum -y update
Enable ELRepo warehouse
ELRepo warehouse is based on Linux for enterprise-class storage, delivery and other community support for RedHat Enterprise (RHEL) RHEL based Linux distributions (CentOS, Scientific, Fedora, etc.).
ELRepo focused on packages and associated hardware, including file system drivers, video drivers, network drivers, sound drivers and the camera driver and the like.
# Import public key ELRepo warehouse
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# Yum install ELRepo warehouse source
rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
3, view the available system kernel package
We can see both versions 4.4 and 4.18
yum --disablerepo="*" --enablerepo="elrepo-kernel" list available Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * elrepo-kernel: mirrors.tuna.tsinghua.edu.cn elrepo-kernel | 2.9 kB 00:00:00 elrepo-kernel/primary_db | 1.8 MB 00:00:03 Available Packages kernel-lt.x86_64 4.4.155-1.el7.elrepo elrepo-kernel kernel-lt-devel.x86_64 4.4.155-1.el7.elrepo elrepo-kernel kernel-lt-doc.noarch 4.4.155-1.el7.elrepo elrepo-kernel kernel-lt-headers.x86_64 4.4.155-1.el7.elrepo elrepo-kernel kernel-lt-tools.x86_64 4.4.155-1.el7.elrepo elrepo-kernel kernel-lt-tools-libs.x86_64 4.4.155-1.el7.elrepo elrepo-kernel kernel-lt-tools-libs-devel.x86_64 4.4.155-1.el7.elrepo elrepo-kernel kernel-ml.x86_64 4.18.7-1.el7.elrepo elrepo-kernel kernel-ml-devel.x86_64 4.18.7-1.el7.elrepo elrepo-kernel kernel-ml-doc.noarch 4.18.7-1.el7.elrepo elrepo-kernel kernel-ml-headers.x86_64 4.18.7-1.el7.elrepo elrepo-kernel kernel-ml-tools.x86_64 4.18.7-1.el7.elrepo elrepo-kernel kernel-ml-tools-libs.x86_64 4.18.7-1.el7.elrepo elrepo-kernel kernel-ml-tools-libs-devel.x86_64 4.18.7-1.el7.elrepo elrepo-kernel perf.x86_64 4.18.7-1.el7.elrepo elrepo-kernel python-perf.x86_64 4.18.7-1.el7.elrepo elrepo-
4, install the latest version of the kernel
$ yum --enablerepo=elrepo-kernel install kernel-ml
--enablerepo
Options open designated warehouse on CentOS systems. Is enabled by default elrepo
, here elrepo-kernel
replaced.
5, set grub2
After a good kernel is installed, you need to take after the default boot option and restart to take effect
View all available cores on the system:
$ sudo awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg 0 : CentOS Linux (4.18.7-1.el7.elrepo.x86_64) 7 (Core) 1 : CentOS Linux (3.10.0-862.11.6.el7.x86_64) 7 (Core) 2 : CentOS Linux (3.10.0-514.el7.x86_64) 7 (Core) 3 : CentOS Linux (0-rescue-063ec330caa04d4baae54c6902c62e54) 7 (Core)
Setting new kernel as the default version of grub2
There are four cores on the server, we want to use this version 4.18, you can grub2-set-default 0
command or edit /etc/default/grub
to set the file
1, the grub2-set-default 0
command sets
Where 0 is check out the available cores above
grub2-set-default 0
Method 2, editing /etc/default/grub
files
Provided GRUB_DEFAULT = 0, the number displayed by the above query as the core 0 is the default kernel:
$ vim /etc/default/grub GRUB_TIMEOUT=5 GRUB_DISTRIBUTOR="$(sed 's, release .*$,,g' /etc/system-release)" GRUB_DEFAULT=0 GRUB_DISABLE_SUBMENU=true GRUB_TERMINAL_OUTPUT="console" GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=cl/root rhgb quiet" GRUB_DISABLE_RECOVERY="true"
Generate grub configuration file and restart
$ grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-4.18.7-1.el7.elrepo.x86_64 Found initrd image: /boot/initramfs-4.18.7-1.el7.elrepo.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-862.11.6.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-862.11.6.el7.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-514.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-514.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-063ec330caa04d4baae54c6902c62e54 Found initrd image: /boot/initramfs-0-rescue-063ec330caa04d4baae54c6902c62e54.img done
$reboot
6. Verify
$ uname -r 4.18.7-1.el7.elrepo.x86_64
7, delete the old kernel (optional)
View all system kernel:
$ rpm -qa | grep kernel kernel-3.10.0-514.el7.x86_64 kernel-ml-4.18.7-1.el7.elrepo.x86_64 kernel-tools-libs-3.10.0-862.11.6.el7.x86_64 kernel-tools-3.10.0-862.11.6.el7.x86_64 kernel-3.10.0-862.11.6.el7.x86_64
Method 1, yum remove delete the old kernel RPM package
$ yum remove kernel-3.10.0-514.el7.x86_64 \
kernel-tools-libs-3.10.0-862.11.6.el7.x86_64 \
kernel-tools-3.10.0-862.11.6.el7.x86_64 \
kernel-3.10.0-862.11.6.el7.x86_64
方法2、yum-utils
tool
If you install a kernel no more than three, yum-utils
the tool does not remove any of them. Only when you install kernel is greater than three, it will automatically delete old kernel.
Install yum-utils
$ yum install yum-utils
Remove the old version
package-cleanup --oldkernels