1- # Creating Custom rootfs and kernel Images
1+ # 创建自定义根文件系统和内核映像
22
3- ## Creating a Linux kernel Image
3+ ## 创建 Linux 内核映像
44
5- ### Manual compilation
5+ ### 手动编译
66
7- Currently, Firecracker supports uncompressed ELF kernel images on x86_64 while
8- on aarch64 it supports PE formatted images.
7+ 目前,Firecracker 在 x86_64 架构上支持未压缩的 ELF 内核映像,而在 aarch64 架构上则支持 PE 格式映像。
98
10- Here's a quick step-by-step guide to building your own kernel that Firecracker
11- can boot:
9+ 以下是快速构建可供 Firecracker 启动的自定义内核的分步指南:
1210
13- 1 . Get the Linux source code:
11+ 1 . 获取 Linux 源代码:
1412
1513 ``` bash
1614 git clone https://github.com/torvalds/linux.git linux.git
1715 cd linux.git
1816 ```
1917
20- 1 . Check out the Linux version you want to build (e.g. we'll be using v4.20
21- here):
18+ 1 . 检出要构建的 Linux 版本(例如,我们这里将使用 v4.20):
2219
2320 ``` bash
2421 git checkout v4.20
2522 ```
2623
27- 1 . You will need to configure your Linux build. You can start from our
28- recommended [ guest kernel configurations] ( ../resources/guest_configs/ ) by
29- copying the relevant one to ` .config ` (under the Linux sources dir). You can
30- make interactive config adjustments using:
24+ 1 . 您需要配置 Linux 构建环境。可从我们推荐的[ 客户机内核配置] ( ../resources/guest_configs/ ) 开始,将相关配置文件复制到 ` .config ` (位于 Linux 源代码目录下)。您可通过以下命令进行交互式配置调整:
3125
3226 ``` bash
3327 make menuconfig
3428 ```
3529
3630> [ !NOTE]
3731>
38- > There are many ways of building a kernel config file, other than ` menuconfig ` .
39- > You are free to use whichever one you choose.
32+ > 构建内核配置文件的方式多种多样,不仅限于 ` menuconfig ` 。
33+ > 您可自由选择任意一种方式。
4034
41- 1 . Build the kernel image:
35+ 1 . 构建内核映像:
4236
4337 ``` bash
4438 arch=$( uname -m)
@@ -49,182 +43,145 @@ can boot:
4943 fi
5044 ```
5145
52- 1 . Upon a successful build, you can find the kernel image under ` ./vmlinux ` (for
53- x86) or ` ./arch/arm64/boot/Image ` (for aarch64).
46+ 1 . 构建成功后,您可以在 ` ./vmlinux ` (x86 架构)或 ` ./arch/arm64/boot/Image ` (aarch64 架构)目录下找到内核映像文件。
5447
55- For a list of currently supported kernel versions, check out the
56- [ kernel support policy] ( kernel-policy.md ) .
48+ 有关当前支持的内核版本列表,请查看[ 内核支持策略] ( kernel-policy.md ) 。
5749
58- ### Use the provided recipe
50+ ### 使用预设方案
5951
60- The kernel images used in our CI to test Firecracker's features are obtained by
61- running the script ` resources/rebuild.sh ` .
52+ 我们在持续集成中用于测试 Firecracker 功能的内核镜像是通过运行脚本` resources/rebuild.sh ` 获取的。
6253
63- Users can build those locally by running:
54+ 用户可通过运行以下命令在本地构建这些内容:
6455
6556``` bash
6657./tools/devtool build_ci_artifacts kernels
6758```
6859
69- This will build all versions that we currently use in our CI. ` kernels `
70- subcommand allows passing a specific kernel version to build. For example:
60+ 这将构建我们当前在 CI 中使用的所有内核版本。` kernels ` 子命令允许传入一个特定的内核版本进行构建。例如:
7161
7262``` bash
7363./tools/devtool build_ci_artifacts kernels 6.1
7464```
7565
76- will build only the 6.1 kernel.
66+ 将仅构建 6.1 内核。
7767
78- Currently supported kernel versions are: ` 5.10 ` , ` 5.10-no-acpi ` (same as 5.10
79- but without ACPI support) and ` 6.1 ` .
68+ 当前支持的内核版本为:` 5.10 ` 、` 5.10-no-acpi ` (与 5.10 相同,但不支持 ACPI)以及 ` 6.1 ` 。
8069
81- After the command finishes, the kernels along with the corresponding KConfig
82- used will be stored under ` resources/$(uname -m) ` .
70+ 命令执行完成后,构建好的内核及其对应的 KConfig 配置文件将被存储在 ` resources/$(uname -m) ` 目录下。
8371
84- ## Creating a Linux rootfs Image
72+ ## 创建 Linux 根文件系统映像
8573
86- A rootfs image is just a file system image, that hosts at least an init system.
87- For instance, our getting started guide uses an ext4 filesystem image. Note
88- that, whichever file system you choose to use, support for it will have to be
89- compiled into the kernel, so it can be mounted at boot time.
74+ 根文件系统映像本质上就是一个文件系统映像,至少包含一个初始化系统。
75+ 例如,我们的入门指南使用的是 ext4 文件系统映像。请注意,无论选择哪种文件系统,都必须将其支持编译到内核中,以便在启动时挂载。
9076
91- In order to obtain an ext4 image that you can use with Firecracker, you have the
92- following options:
77+ 要获取可与 Firecracker 配合使用的 ext4 映像,您有以下几种选择:
9378
94- ### Manual build
79+ ### 手动构建
9580
96- 1 . Prepare a properly-sized file. We'll use 50MiB here, but this depends on how
97- much data you'll want to fit inside:
81+ 1 . 准备大小合适的文件。此处使用 50MiB,但具体取决于您希望放入多少数据:
9882
9983 ``` bash
10084 dd if=/dev/zero of=rootfs.ext4 bs=1M count=50
10185 ```
10286
103- 1 . Create an empty file system on the file you created:
87+ 1 . 在创建的文件上建立空文件系统:
10488
10589 ``` bash
10690 mkfs.ext4 rootfs.ext4
10791 ```
10892
109- You now have an empty EXT4 image in ` rootfs.ext4 ` , so let's prepare to populate
110- it. First, you'll need to mount this new file system, so you can easily access
111- its contents:
93+ 此时` rootfs.ext4 ` 已生成空的 EXT4 映像,接下来准备填充内容。首先需挂载新文件系统以便访问其内容:
11294
11395``` bash
11496mkdir /tmp/my-rootfs
11597sudo mount rootfs.ext4 /tmp/my-rootfs
11698```
11799
118- The minimal init system would be just an ELF binary, placed at ` /sbin/init ` . The
119- final step in the Linux boot process executes ` /sbin/init ` and expects it to
120- never exit. More complex init systems build on top of this, providing service
121- configuration files, startup / shutdown scripts for various services, and many
122- other features.
100+ 最简化的初始化系统仅是一个 ELF 二进制文件,位于` /sbin/init ` 路径下。Linux 启动过程的最后一步会执行` /sbin/init ` ,并期望该程序永不退出。更复杂的初始化系统在此基础上构建,提供服务配置文件、各类服务的启动/关闭脚本以及诸多其他功能。
123101
124- For the sake of simplicity, let's set up an Alpine-based rootfs, with OpenRC as
125- an init system. To that end, we'll use the official Docker image for Alpine
126- Linux:
102+ 为简化操作,我们建立一个基于 Alpine 的根文件系统,并采用 OpenRC 作为初始化系统。为此,我们将使用官方的 Alpine Linux Docker 镜像:
127103
128- 1 . First, let's start the Alpine container, bind-mounting the EXT4 image created
129- earlier, to ` /my-rootfs ` :
104+ 1 . 首先启动 Alpine 容器,将先前创建的 EXT4 镜像挂载到 ` /my-rootfs ` :
130105
131106 ``` bash
132107 docker run -it --rm -v /tmp/my-rootfs:/my-rootfs alpine
133108 ```
134109
135- 1 . Then, inside the container, install the OpenRC init system, and some basic
136- tools:
110+ 1 . 然后,在容器内部安装 OpenRC 初始化系统以及一些基本工具:
137111
138112 ``` bash
139113 apk add openrc
140114 apk add util-linux
141115 ```
142116
143- 1 . And set up userspace init (still inside the container shell):
117+ 1 . 并设置用户空间初始化程序(仍处于容器 shell 中):
144118
145119 ``` bash
146- # Set up a login terminal on the serial console ( ttyS0):
120+ # 在串行控制台( ttyS0)上设置登录终端:
147121 ln -s agetty /etc/init.d/agetty.ttyS0
148122 echo ttyS0 > /etc/securetty
149123 rc-update add agetty.ttyS0 default
150124
151- # Make sure special file systems are mounted on boot:
125+ # 确保特殊文件系统在启动时挂载:
152126 rc-update add devfs boot
153127 rc-update add procfs boot
154128 rc-update add sysfs boot
155129
156- # Then, copy the newly configured system to the rootfs image:
130+ # 然后,将新配置的系统复制到根文件系统映像中:
157131 for d in bin etc lib root sbin usr; do tar c " /$d " | tar x -C /my-rootfs; done
158132
159- # The above command may trigger the following message:
133+ # 上述命令可能会触发以下提示:
160134 # tar: Removing leading "/" from member names
161- # However, this is just a warning, so you should be able to
162- # proceed with the setup process.
135+ # 但这仅为警告信息,您仍可继续执行设置流程。
163136
164137 for dir in dev proc run sys var; do mkdir /my-rootfs/${dir} ; done
165138
166- # All done, exit docker shell.
139+ # 完成,退出 Docker 终端。
167140 exit
168141 ```
169142
170- 1 . Finally, unmount your rootfs image:
143+ 1 . 最后,卸载您的根文件系统映像:
171144
172145 ``` bash
173146 sudo umount /tmp/my-rootfs
174147 ```
175148
176- ### Use the provided recipe
149+ ### 使用预设配置
177150
178- The disk images used in our CI to test Firecracker's features are obtained by
179- using the recipe (in a Ubuntu 22.04 host):
151+ 我们 CI 中用于测试 Firecracker 功能的磁盘镜像,是通过以下方法(在 Ubuntu 22.04 主机上)生成的:
180152
181153``` bash
182154./tools/devtool build_ci_artifacts rootfs
183155```
184156
185- The images resulting using this method are minimized Ubuntu 22.04. Feel free to
186- adjust the script(s) to suit your use case.
157+ 使用此方法生成的镜像为精简版 Ubuntu 22.04。请根据实际需求自由调整脚本。
187158
188- You should now have a rootfs image (` ubuntu-22.04.ext4 ` ), that you can boot with
189- Firecracker.
159+ 您现在应获得一个根文件系统镜像(` ubuntu-22.04.ext4 ` ),可通过 Firecracker 进行引导。
190160
191- ## Creating FreeBSD rootfs and kernel Images
161+ ## 创建 FreeBSD 根文件系统和内核映像
192162
193- Here's a quick step-by-step guide to building a FreeBSD rootfs and kernel that
194- Firecracker can boot:
163+ 以下是快速构建 FreeBSD 根文件系统和内核的分步指南,Firecracker 可由此启动:
195164
196- 1 . Boot a FreeBSD system. In EC2, the
197- [ FreeBSD 13 Marketplace image] ( https://aws.amazon.com/marketplace/pp/prodview-ukzmy5dzc6nbq )
198- is a good option; you can also use weekly snapshot AMIs published by the
199- FreeBSD project. (Firecracker support is in FreeBSD 14 and later, so you'll
200- need FreeBSD 13 or later to build it.)
165+ 1 . 启动 FreeBSD 系统。在 EC2 中,[ FreeBSD 13 市场映像] ( https://aws.amazon.com/marketplace/pp/prodview-ukzmy5dzc6nbq ) 是不错的选择;您也可以使用 FreeBSD 项目发布的每周快照 AMI。(Firecracker 支持需 FreeBSD 14 及以上版本,因此构建时需使用 FreeBSD 13 或更高版本。)
201166
202- The build will require about 50 GB of disk space, so size the disk
203- appropriately.
167+ 构建过程约需 50 GB 磁盘空间,请预留足够容量。
204168
205- 1 . Log in to the FreeBSD system and become root. If using EC2, you'll want to
206- ssh in as ` ec2-user ` with your chosen SSH key and then ` su ` to become root.
169+ 1 . 登录 FreeBSD 系统并获取 root 权限。若使用 EC2,请通过 SSH 以` ec2-user ` 身份登录(需使用预先配置的 SSH 密钥),随后执行` su ` 切换至 root 用户。
207170
208- 1 . Install git and check out the FreeBSD src tree:
171+ 1 . 安装 git 并检出 FreeBSD 源代码树:
209172
210173 ``` sh
211174 pkg install -y git
212175 git clone https://git.freebsd.org/src.git /usr/src
213176 ```
214177
215- Firecracker support is available since FreeBSD 14.0 (released November 2023).
178+ 自 FreeBSD 14.0 版本(2023 年 11 月发布)起支持 Firecracker。
216179
217- 1 . Build FreeBSD:
180+ 1 . 构建 FreeBSD:
218181
219182 ``` sh
220183 make -C /usr/src buildworld buildkernel KERNCONF=FIRECRACKER
221184 make -C /usr/src/release firecracker DESTDIR=` pwd`
222185 ```
223186
224- You should now have a rootfs ` freebsd-rootfs.bin ` and a kernel
225- ` freebsd-kern.bin ` in the current directory (or elsewhere if you change the
226- ` DESTDIR ` value) that you can boot with Firecracker. Note that the FreeBSD
227- rootfs generated in this manner is somewhat minimized compared to "stock"
228- FreeBSD; it omits utilities which are only relevant on physical systems (e.g.,
229- utilities related to floppy disks, USB devices, and some network interfaces) and
230- also debug files and the system compiler.
187+ 你现在应该在当前目录(或者如果你修改了 DESTDIR 的值,则在指定目录)中得到了一个 rootfs 文件 freebsd-rootfs.bin 和一个内核文件 freebsd-kern.bin,它们可以直接用于 Firecracker 启动。需要注意的是,通过这种方式生成的 FreeBSD rootfs 相比“标准版” FreeBSD 已经过一定程度的精简;它移除了仅在物理系统上有用的工具(例如与软盘、USB 设备和某些网络接口相关的工具),同时也去除了调试文件和系统编译器。
0 commit comments