# 10.6.如果发生了错误

在构建自定义内核时，可能会遇到四种类型的故障：

**`config` 失败**

如果 `config` 失败，它会打印出错误的行号。例如，对于以下消息，请确保第 17 行输入正确，可以与 GENERIC 或 NOTES 文件进行比较：

```sh
config: line 17: syntax error
```

**`make` 失败**

如果 `make` 失败，通常是由于内核配置文件中的错误，但该错误没有严重到被 `config` 检测到。请检查配置文件，如果问题不明显，可以将内核配置文件发送到 [FreeBSD 常见问题邮件列表](https://lists.freebsd.org/subscription/freebsd-questions) 求助。

**内核无法启动**

如果新内核无法启动或无法识别设备，不必惊慌！幸运的是，FreeBSD 提供了一个优秀的机制来从不兼容的内核中恢复。只需在 FreeBSD 启动加载器中选择要启动的内核。在系统启动菜单出现时，选择 "Escape to a loader prompt" 选项。在提示符下，输入 `boot kernel.old`，或者输入任何已知能正常启动的内核名称。

在使用一个可用的内核启动后，请检查配置文件并尝试重新构建。一个有用的资源是 /var/log/messages，它记录了每次成功启动的内核信息。另外，[dmesg(8)](https://man.freebsd.org/cgi/man.cgi?query=dmesg\&sektion=8\&format=html) 会打印当前启动的内核信息。

```sh
# mv /boot/kernel /boot/kernel.bad
# mv /boot/kernel.good /boot/kernel
```

**内核正常工作，但** [**ps(1)**](https://man.freebsd.org/cgi/man.cgi?query=ps\&sektion=1\&format=html) **无法使用**

如果内核版本与系统工具的构建版本不同，例如，在 -RELEASE 系统上安装了从 -CURRENT 源代码构建的内核，那么许多系统状态命令，如 [ps(1)](https://man.freebsd.org/cgi/man.cgi?query=ps\&sektion=1\&format=html) 和 [vmstat(8)](https://man.freebsd.org/cgi/man.cgi?query=vmstat\&sektion=8\&format=html)，将无法工作。为了解决这个问题，请 [重新编译并安装与内核版本相同的世界文件](https://docs.freebsd.org/en/books/handbook/cutting-edge/#makeworld)。使用与操作系统其他部分版本不同的内核版本从来不是一个好主意。


---

# 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://handbook.bsdcn.org/di-10-zhang-pei-zhi-freebsd-nei-he/10.6.-ru-guo-fa-sheng-le-yi-xie-cuo-wu.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.
