Linux - 修改內核啟動順序及刪除無用內核
阿新 • • 發佈:2017-12-02
sum name ade gin nis db4 pre transacti 內核啟動
現象:
CentOS7開機啟動界面顯示多個內核選項
原因:
正常情況下,有兩個啟動項,一個是“正常啟動”,另一個是“救援模式啟動”(rescue)。
如果啟動項多於2個,說明當前系統有舊內核未刪除。原因是CentOS更新後不會自動刪除舊內核。
默認以新內核啟動,可以在啟動選項中臨時選擇,也可以修改配置永久指定。
示例:修改默認啟動的內核
[root@CentOS-7 ~]# uname -r # 查看當前內核版本
3.10.0-693.5.2.el7.x86_64
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# cat /boot/grub2/grub.cfg |grep "menuentry " # 查看所有可用內核
menuentry ‘CentOS Linux (3.10.0-693.5.2.el7.x86_64) 7 (Core)‘ --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option ‘gnulinux-3.10.0-327.el7.x86_64-advanced-88ae7d3d-ffaf-4402-9d44-56b6845789e4‘ {
menuentry ‘CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core)‘ --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option ‘gnulinux-3.10.0-327.el7.x86_64-advanced-88ae7d3d-ffaf-4402-9d44-56b6845789e4‘ {
menuentry ‘CentOS Linux (0-rescue-8405cda22c0b421db40478edcf9c1fb2) 7 (Core)‘ --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option ‘gnulinux-0-rescue-8405cda22c0b421db40478edcf9c1fb2-advanced-88ae7d3d-ffaf-4402-9d44-56b6845789e4‘ {
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# grub2-set-default ‘CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core)‘
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# grub2-editenv list # 查看內核修改結果
saved_entry=CentOS Linux (3.10.0-327.el7.x86_64) 7 (Core)
[root@CentOS-7 ~]#
示例:刪除無用內核
[root@CentOS-7 ~]# uname -r # 查看當前內核版本
3.10.0-693.5.2.el7.x86_64
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# rpm -qa |grep kernel-[0-9] # 查看全部內核包
kernel-3.10.0-693.5.2.el7.x86_64
kernel-3.10.0-327.el7.x86_64
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# yum remove kernel-3.10.0-327.el7.x86_64 # 刪除指定的無用內核
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package kernel.x86_64 0:3.10.0-327.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
=============================================================================================================================================================
Package Arch Version Repository Size
=============================================================================================================================================================
Removing:
kernel x86_64 3.10.0-327.el7 @anaconda 136 M
Transaction Summary
=============================================================================================================================================================
Remove 1 Package
Installed size: 136 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : kernel-3.10.0-327.el7.x86_64 1/1
Verifying : kernel-3.10.0-327.el7.x86_64 1/1
Removed:
kernel.x86_64 0:3.10.0-327.el7
Complete!
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# rpm -qa |grep kernel-[0-9] # 查看全部內核包
kernel-3.10.0-693.5.2.el7.x86_64
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# cat /boot/grub2/grub.cfg |grep "menuentry "
menuentry ‘CentOS Linux (3.10.0-693.5.2.el7.x86_64) 7 (Core)‘ --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option ‘gnulinux-3.10.0-327.el7.x86_64-advanced-88ae7d3d-ffaf-4402-9d44-56b6845789e4‘ {
menuentry ‘CentOS Linux (0-rescue-8405cda22c0b421db40478edcf9c1fb2) 7 (Core)‘ --class centos --class gnu-linux --class gnu --class os --unrestricted $menuentry_id_option ‘gnulinux-0-rescue-8405cda22c0b421db40478edcf9c1fb2-advanced-88ae7d3d-ffaf-4402-9d44-56b6845789e4‘ {
[root@CentOS-7 ~]#
Linux - 修改內核啟動順序及刪除無用內核