# 在grub2中切换默认启动内核

* 检查可使用的内核启动选项列表

```
#awk -F\' '$1=="menuentry " {print i++ " : " $2}' /etc/grub2.cfg
```

显示输出有3个启动内核选项

```
0 : CentOS Linux (3.10.0-514.21.2.el7.x86_64) 7 (Core)
1 : CentOS Linux (3.10.0-327.ali2010.alios7.x86_64) 7 (Core)
2 : CentOS Linux (0-rescue-fcb7caa23aaf46d0ba593dd2232c0fad) 7 (Core)
```

* 检查当前默认启动项

```
#grub2-editenv list
```

```
saved_entry=CentOS Linux (3.10.0-514.21.2.el7.x86_64) 7 (Core)
```

* 调整设置，选择`1`作为启动项

```
#grub2-set-default 1
```

> 这里也可以使用`grub2-set-default "CentOS Linux (3.10.0-327.ali2010.alios7.x86_64) 7 (Core)"`，这样使用`grub2-editenv list`就会显示`saved_entry=CentOS Linux (3.10.0-327.ali2010.alios7.x86_64) 7 (Core)`。实际上，这个配置写入在`/boot/grub2/grubenv`文件中，可以直接通过`sudo cat /boot/grub2/grubenv`查看。

* 再次检查确认启动项

```
#grub2-editenv list
saved_entry=1
```

* 重启操作系统，即切换默认内核

## 参考

* [Setting Up grub2 on CentOS7 - 2. How to Define the Default Entries](https://wiki.centos.org/HowTos/Grub2)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://huataihuang.gitbook.io/cloud-atlas-draft/os/linux/redhat/system_administration/grub2/switch_default_kernel_in_grub2.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
