系统信息参考

[tony@tony-dev ~]$ cat /etc/redhat-release
CentOS Linux release 7.6.1810 (Core)

GRUB的配置文件

在启用了UEFI的系统上,CentOS 7的GRUB的有效配置文件是 /boot/efi/EFI/centos/grub.cfg。/boot/grub与/boot/grub2目录下已经不再保存配置文件 (参看后图)。

查看一下这个文件的头部说明,可以看到 “不可编辑这个文件”的警告信息,同时指明了修改这个文件的方法:即需要修改/etc/default/grub配置文件与/etc/grub.d目录下的模板后,再用grub2-mkconfig命令生成这个文件

[root@tony-dev boot]# sudo cat /boot/efi/EFI/centos/grub.cfg
#
# DO NOT EDIT THIS FILE
#
# It is automatically generated by grub2-mkconfig using templates
# from /etc/grub.d and settings from /etc/default/grub

#

# /boot目录结构图
[root@tony-dev boot]# tree -F /boot
/boot
├── config-3.10.0-693.11.6.el7.x86_64
    ...
├── efi/
│   └── EFI/
│       ├── BOOT/
│       │   ├── BOOTX64.EFI*
│       │   ├── fallback.efi*
│       │   └── fbx64.efi*
│       └── centos/
│           ├── BOOT.CSV*
│           ├── BOOTX64.CSV*
│           ├── fonts/
│           │   └── unicode.pf2*
│           ├── fw/
│           ├── fwupia32.efi*
│           ├── fwupx64.efi*
│           ├── grub.cfg*
│           ├── grub.cfg.1554740803.rpmsave*
│           ├── grubenv*
│           ├── grubx64.efi*
│           ├── mmx64.efi*
│           ├── MokManager.efi*
│           ├── shim.efi*
│           ├── shimx64-centos.efi*
│           └── shimx64.efi*
├── grub/
│   └── splash.xpm.gz
├── grub2/
│   └── grubenv -> ../efi/EFI/centos/grubenv*
├── initramfs-0-rescue-2282c2e0651e46f796865aaa645ac7fe.img
    ...
├── lost+found/
├── symvers-3.10.0-693.11.6.el7.x86_64.gz
    ...
├── vmlinuz-0-rescue-2282c2e0651e46f796865aaa645ac7fe*
    ...
└── vmlinuz-3.10.0-957.10.1.el7.x86_64.debug*

9 directories, 56 files

查找grub.cfg文件

# 通常会打印出
# /boot/efi/EFI/centos/grub.cfg (UEFI-based system)
# 或者
# /boot/grub2/grub.cfg (Legacy system)

[tony@tony-dev ~]$ sudo find /boot -name grub.cfg
/boot/efi/EFI/centos/grub.cfg

列出所有的引导入口

# 用单引号(')作分隔符,第一个域是"menuentry "的行,就是引导入口。
[root@tony-dev default]# awk -F\' '$1=="menuentry " {print i++ " : " $2}' $(find /boot -name grub.cfg)
0 : CentOS Linux (3.10.0-957.10.1.el7.x86_64.debug) 7 (Core)
1 : CentOS Linux (3.10.0-957.10.1.el7.x86_64) 7 (Core)
2 : CentOS Linux (3.10.0-693.11.6.el7.x86_64) 7 (Core)
3 : CentOS Linux (3.10.0-693.el7.centos.tony_base.x86_64.debug) 7 (Core)
4 : CentOS Linux (3.10.0-693.el7.centos.tony_base.x86_64) 7 (Core)
5 : CentOS Linux (3.10.0-693.el7.x86_64) 7 (Core)
6 : CentOS Linux (0-rescue-2282c2e0651e46f796865aaa645ac7fe) 7 (Core)

列出默认的引导入口

[root@tony-dev default]# grub2-editenv list
saved_entry=CentOS Linux (3.10.0-957.10.1.el7.x86_64) 7 (Core)

修改默认的引导入口

[root@tony-dev default]# grub2-set-default 2
[root@tony-dev default]# grub2-editenv list
saved_entry=2

/etc/default/grub文件

默认的/etc/default/grub文件并不长,内容如下:

[root@tony-dev default]# cat /etc/default/grub

GRUB_TIMEOUT=5
GRUB_DISTRIBUTOR="$(sed ‘s, release .*$,g’ /etc/system-release)"
GRUB_DEFAULT=saved
GRUB_DISABLE_SUBMENU=true
GRUB_TERMINAL_OUTPUT=“console”
GRUB_CMDLINE_LINUX=“crashkernel=auto rhgb quiet”
GRUB_DISABLE_RECOVERY=“true”

重新生成/etc/default/grub文件

修改配置文件后,需要使用如下命令重新生成grub.cfg文件,以使配置文件生效。

grub2-mkconfig -o $(find /boot -name grub.cfg)

打印出所有安装的内核

[tony@tony-dev ~]$ sudo rpm -q kernel
kernel-3.10.0-693.el7.x86_64
kernel-3.10.0-693.el7.centos.tony_base.x86_64
kernel-3.10.0-693.11.6.el7.x86_64
kernel-3.10.0-957.10.1.el7.x86_64

删除指定的内核

[root@tony-dev boot]# sudo yum remove kernel-3.10.0-693.el7.centos.tony_base.x86_64

Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
–> Running transaction check
—> Package kernel.x86_64 0:3.10.0-693.el7.centos.tony_base will be erased
–> Finished Dependency Resolution
&npsb;
Dependencies Resolved
&npsb;
================================================================================
Package Arch Version Repository Size
================================================================================
Removing:
kernel x86_64 3.10.0-693.el7.centos.tony_base installed 59 M
&npsb;
Transaction Summary
================================================================================
Remove 1 Package
&npsb;
Installed size: 59 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-693.el7.centos.tony_base.x86_64 1/1
Verifying : kernel-3.10.0-693.el7.centos.tony_base.x86_64 1/1
&npsb;
Removed:
kernel.x86_64 0:3.10.0-693.el7.centos.tony_base
&npsb;
Complete!

Logo

更多推荐