> 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/4.3-bsd-unix-cao-zuo-xi-tong-she-ji-yu-shi-xian/di-wu-bu-fen-xi-tong-yun-xing/13.2.-zi-ju.md).

# 13.2 自举

自举一个程序是依赖机器的操作。多数机器上，这一操作由称为控制台处理器（console processor）的辅助处理器或控制台监视器（console monitor）支持。控制台监视器程序驻留在非易失存储中，CPU 复位时自动被调起。控制台设施应支持独立程序的引导。多数控制台处理器和监视器在机器复位时还执行诊断操作，确保硬件正常。

**boot 程序**

控制台处理器或控制台监视器往往不懂 4.3BSD 文件系统的格式；支持自举操作的软件解读的是厂商专有文件系统格式或其他格式。因此，UNIX 内核历来经 **boot** 程序自举。这个程序是一个通用的 **独立** 程序，可用来装入和执行其他独立程序。独立程序（standalone program）是无须 UNIX 内核协助即可运作的程序，通常与独立 I/O 库（standalone I/O library）链接——该库在多种硬件设备上支持类 UNIX 的 I/O 接口。独立 I/O 库经一组独立设备驱动和一组支持从设备上的 UNIX 文件系统读文件的例程提供这些设施。

**boot** 程序装入并启动后，必须装入含待自举程序可执行映像的文件，然后启动装入的程序。要装入正确的文件，**boot** 必须知道待装入文件的路径名和文件所在的硬件设备。这一信息以两种方式之一传达给 **boot**：VAX 上，初始化两个硬件寄存器，其值规定 **boot** 应如何运作、装入程序映像时用哪个设备；其他机器则靠初始化运行时栈、把参数放上栈来传达自举信息，方式与 UNIX 内核向程序传参相同。

VAX 用的寄存器称为 boothowto 寄存器和 bootdevice 寄存器。**boot** 启动运行时解释 boothowto 寄存器：视其值，**boot** 或从 bootdevice 寄存器指定的设备装入文件 **vmunix**，或在控制台终端提示输入要装入的文件名和获取该文件的设备。放进 boothowto 寄存器的值由表 13.1 的标志定义；放进 bootdevice 寄存器、标识自举所用硬件设备的值取决于与 **boot** 链接的独立 I/O 库的配置——该库的构成取决于机器上可用的硬件设备，bootdevice 寄存器的内容因机器类型而异。就我们的讨论而言，知道寄存器内容指定读取程序的默认设备和文件系统分区即可。

表 13.1 传给 boot 程序和 reboot 系统调用的标志

| 标志           | 描述                     |
| ------------ | ---------------------- |
| RB\_ASKNAME  | 提示输入要自举的文件名            |
| RB\_SINGLE   | 自举系统到单用户运行             |
| RB\_NOSYNC†  | 重启前不做 sync             |
| RB\_HALT†    | 不重启，只停机                |
| RB\_INITNAME | 用给定的名字代替 **/etc/init** |
| RB\_DFLTROOT | 用编译进内核的根设备             |
| RB\_KDB      | 把控制交给内核调试器             |
| RB\_RDONLY   | 只读挂载根文件系统              |
| RB\_DUMP†    | 重启前转储内核内存              |

† 仅对 `reboot` 系统调用有意义。

**boot** 总是把程序装到内存位置 0。**boot** 自己起初就装在位置 0，必须先把自己的映像复制到内存他处，免得把它自举的程序映像装到自己头上（见图 13.1）。这一 **重定位** 意味着创建 **boot** 程序时必须把起始地址设为它将被复制到的内存位置；否则 **boot** 被复制后，对其中数据结构的引用会访问错误的内存位置（记住 **boot** 在虚拟地址转换禁止下运作）。

![图 13.1 boot 程序在内存中的位置](https://1991889543-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FilVST9xTgD47M0g8ham7%2Fuploads%2Fgit-blob-4b3f791e4dbd634dece79a2b79b7b215a982ddf5%2Ffig-13-1-figure-13-1-placement.png?alt=media)

**VAX 控制台介质**

多数 VAX 计算机含控制台处理器和某种控制台处理器可访问的辅存。VAX-11/780 的控制台子系统含软盘驱动器，VAX-11/750 和 VAX-11/730 的控制台子系统含小型盒式磁带驱动器。

VAX 自举的确切步骤因机器而异。正常运行时，VAX 控制台处理器在自己的控制台介质上搜索名为 **DEFBOO.CMD** 的文件。这个文件含控制台处理器为自举 CPU 应解释的命令，典型地复位 CPU 和 I/O 子系统、把寄存器初始化为已知值，然后从控制台存储设备装入一个文件并启动它。用户在某些 VAX 机器上可以靠拨面板开关或在控制台终端敲特殊命令要求别的动作。

自举过程用到控制台存储设备时，**boot** 程序必须驻留在该存储设备上。4.3BSD 支持两个操纵控制台处理器所用文件系统格式的工具程序——**arff** 和 **flcopy**，用来把 **boot** 等程序放到 VAX 控制台存储介质上。


---

# 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://book.bsdcn.org/4.3-bsd-unix-cao-zuo-xi-tong-she-ji-yu-shi-xian/di-wu-bu-fen-xi-tong-yun-xing/13.2.-zi-ju.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
