> For the complete documentation index, see [llms.txt](https://book.bsdcn.org/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://book.bsdcn.org/developers-handbook/di-san-bu-fen-nei-he/di-9-zhang-gou-jian-he-an-zhuang-freebsd-nei-he.md).

# 第 9 章 构建和安装 FreeBSD 内核

作为内核开发人员，了解内核构建过程是必要的。调试 FreeBSD 内核时，必须能够构建一个内核。已知有两种构建内核的方法：

支持的构建和安装内核的过程在 FreeBSD 手册的 [构建和安装自定义内核](https://docs.freebsd.org/en/books/handbook/kernelconfig/#kernelconfig-building) 章节中说明。

> **注意**
>
> 本章节假设读者已经熟悉 FreeBSD 手册中的 [构建和安装自定义内核](https://docs.freebsd.org/en/books/handbook/kernelconfig/#kernelconfig-building) 章节中描述的信息。如果尚不熟悉，请阅读上述章节，了解构建过程的工作原理。

## 9.1. 更快但脆弱的构建方法

这种方法在进行内核代码开发时可能会更有用，并且在仅调整内核配置文件中的一个或两个选项时，实际可能比文档中描述的过程更快。另一方面，它可能会导致内核构建出现意外的中断。

1. 运行 [config(8)](https://man.freebsd.org/cgi/man.cgi?query=config\&sektion=8\&format=html) 来生成内核源代码：

   ```sh
   # /usr/sbin/config MYKERNEL
   ```
2. 进入构建目录。如上所述运行 [config(8)](https://man.freebsd.org/cgi/man.cgi?query=config\&sektion=8\&format=html) 后，会打印出此目录的名称。

   ```sh
   # cd ../compile/MYKERNEL
   ```
3. 编译内核：

   ```sh
   # make depend
   # make
   ```
4. 安装新内核：

   ```sh
   # make install
   ```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://book.bsdcn.org/developers-handbook/di-san-bu-fen-nei-he/di-9-zhang-gou-jian-he-an-zhuang-freebsd-nei-he.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
