# 查看内核启动顺序 [root@dev-node-1 ~]# awk -F \' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg 0 : CentOS Linux (4.4.241-1.el7.elrepo.x86_64) 7 (Core) 1 : CentOS Linux (3.10.0-1127.19.1.el7.x86_64) 7 (Core) 2 : CentOS Linux (3.10.0-1127.13.1.el7.x86_64) 7 (Core) 3 : CentOS Linux (0-rescue-4acec6de0e4741b6bc249381506fa844) 7 (Core) 4 : CentOS Linux (0-rescue-0ea734564f9a4e2881b866b82d679dfc) 7 (Core) 或 # 查看系统可用内核 [root@dev-node-1 ~]# grep "^menuentry" /boot/grub2/grub.cfg | cut -d "'" -f2 CentOS Linux (4.4.241-1.el7.elrepo.x86_64) 7 (Core) CentOS Linux (3.10.0-1127.19.1.el7.x86_64) 7 (Core) CentOS Linux (3.10.0-1127.13.1.el7.x86_64) 7 (Core) CentOS Linux (0-rescue-4acec6de0e4741b6bc249381506fa844) 7 (Core) CentOS Linux (0-rescue-0ea734564f9a4e2881b866b82d679dfc) 7 (Core)
1 2 3
# 查看当前实际启动顺序 [root@dev-node-1 ~]# grub2-editenv list saved_entry=CentOS Linux (3.10.0-1127.19.1.el7.x86_64) 7 (Core)
设置默认启动
1
[root@dev-node-1 ~]# grub2-set-default "CentOS Linux (4.4.241-1.el7.elrepo.x86_64) 7 (Core)"
或者
1
grub2-set-default 0 // 0代表查看内核启动顺序时的序号
或者
1 2 3
# 编辑/etc/default/grub文件 vim /etc/default/grub GRUB_DEFAULT=saved 改为GRUB_DEFAULT=0
生成grub配置文件
1 2 3 4 5 6 7 8 9 10 11 12 13
[root@dev-node-1 ~]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-4.4.241-1.el7.elrepo.x86_64 Found initrd image: /boot/initramfs-4.4.241-1.el7.elrepo.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-1127.19.1.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-1127.19.1.el7.x86_64.img Found linux image: /boot/vmlinuz-3.10.0-1127.13.1.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-1127.13.1.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-4acec6de0e4741b6bc249381506fa844 Found initrd image: /boot/initramfs-0-rescue-4acec6de0e4741b6bc249381506fa844.img Found linux image: /boot/vmlinuz-0-rescue-0ea734564f9a4e2881b866b82d679dfc Found initrd image: /boot/initramfs-0-rescue-0ea734564f9a4e2881b866b82d679dfc.img done