Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# imageTailor 使用指南
## 简介
操作系统除内核外,还包含各种功能的外围包。通用操作系统包含较多外围包,提供了丰富的功能,但是这也带来了一些影响:
- 占用资源(内存、磁盘、CPU 等)多,导致系统运行效率低
- 很多功能用户不需要,增加了开发和维护成本
因此,openEuler 提供了 imageTailor 镜像裁剪定制工具。用户可以根据需求裁剪操作系统镜像中不需要的外围包,或者添加所需的业务包或文件。该工具主要提供了以下功能:
- 系统包裁剪定制:用户可以选择默认安装以及裁剪的rpm,也支持用户裁剪定制系统命令、库、驱动。
- 系统配置定制:用户可以配置主机名、启动服务、时区、网络、分区、加载驱动、版本号等。
- 用户文件定制:支持用户添加定制文件到系统镜像中。
## 安装工具
本节以 openEuler 23.03 版本 riscv64 架构为例,说明安装方法。
### 软硬件要求
安装和运行 imageTailor 需要满足以下软硬件要求:
- 机器架构为 x86_64、AArch64 或 riscv64
- 操作系统为 openEuler 23.03(该版本内核版本为 6.1,python 版本为 3.10.9,满足工具要求)
- 运行工具的机器根目录 '/' 需要 40 GB 以上空间
- python 版本 3.9 及以上
- kernel 内核版本 5.10 及以上
- 关闭 SElinux 服务
```shell
$ sudo setenforce 0
$ getenforce
Permissive
```
### 安装 imageTailor
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
1. 确认机器已经安装操作系统 openEuler 23.03(imageTailor 工具的运行环境)。
```shell
$ cat /etc/openEuler-release
openEuler release 23.03
```
2. 使用 root 权限,安装 imageTailor 裁剪工具:
> 目前 imageTailor 暂未被合入至主线,可能需要事先在 `/etc/yum.repos.d/openEuler.repo` 内添加软件源后执行安装。
```shell
sudo yum install -y imageTailor
```
3. 使用 root 权限,确认工具已安装成功。
```shell
$ cd /opt/imageTailor/
$ sudo ./mkdliso -h
-------------------------------------------------------------------------------------------------------------
Usage: mkdliso -p product_name -c configpath [--minios yes|no|force] [-h] [--sec]
Options:
-p,--product Specify the product to make, check custom/cfg_yourProduct.
-c,--cfg-path Specify the configuration file path, the form should be consistent with custom/cfg_xxx
--minios Make minios: yes|no|force
--sec Perform security hardening
-h,--help Display help information
Example:
command:
./mkdliso -p openEuler -c custom/cfg_openEuler --sec
help:
./mkdliso -h
-------------------------------------------------------------------------------------------------------------
```
## 制作系统
本章介绍使用 imageTailor 工具生成 qcow2 镜像。
> 注意,目前 riscv64 架构生成的 qcow2 镜像仅支持从 QEMU 启动,且目前也仅支持生成 qcow2 镜像。目前也暂时不支持定制 qcow2 镜像。
### 配置系统参数
开始制作操作系统 qcow2 镜像之前,需要配置系统参数,包括主机参数、初始密码、分区、网络、编译参数和系统命令行参数。
#### 配置镜像源
`/opt/imageTailor/custom/cfg_qcow2/repo` 文件用于镜像源的设置。可以在这里添加你需要的软件源。
#### 配置预装软件包
`/opt/imageTailor/custom/cfg_qcow2/rpmlist` 文件用于软件包的设置。可以在这里添加你需要的软件包。
#### 配置 root 初始密码
##### 简介
root 初始密码保存在 `/opt/imageTailor/custom/cfg_openEuler/rpm.conf` 中,用户通过修改该文件配置 root 初始密码。
/opt/imageTailor/custom/cfg_openEuler/rpm.conf 中 root 初始密码的默认配置为 `openEuler12#$`,用户可以自行更改:
```
$6$o4rTi3d/.hh6JUYC$ClnCxd2mAQHlt0UloC4ystQg0CiuSVyhXz0sP1mDCNCgWV0rBwegwJ/bCWfjN4WxbahDa7F9U3c6/vFaNgsvX/
```
用户初始密码的加密密文,加密算法为 SHA-512。
##### 修改方法
这里给出设置 root 初始密码的方法(需使用 root 权限):
1. 添加用于生成密码的用户,此处假设 testUser。
```shell
sudo useradd testUser
```
2. 设置 testUser 用户的密码。参考命令如下,根据提示设置密码:
```shell
$ sudo passwd testUser
Changing password for user testUser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
```
3. 查看 /etc/shadow 文件,testUser 后的内容(两个 : 间的字符串)即为加密后的密码。
``` shell script
$ sudo cat /etc/shadow | grep testUser
testUser:$6$YkX5uFDGVO1VWbab$jvbwkZ2Kt0MzZXmPWy.7bJsgmkN0U2gEqhm9KqT1jwQBlwBGsF3Z59heEXyh8QKm3Qhc5C3jqg2N1ktv25xdP0:19052:0:90:7:35::
```
4. 拷贝上述加密密码替换 `/opt/imageTailor/custom/cfg_openEuler/rpm.conf` 中的密码,如下所示:
```
$6$YkX5uFDGVO1VWbab$jvbwkZ2Kt0MzZXmPWy.7bJsgmkN0U2gEqhm9KqT1jwQBlwBGsF3Z59heEXyh8QKm3Qhc5C3jqg2N1ktv25xdP0
```
### 制作指导
可以通过 mkdliso 脚本制作系统镜像文件。使用 mkdliso 制作 qcow2 镜像的操作步骤如下:
1. 使用 root 权限,执行 mkdliso 命令,生成 qcow2 镜像文件。参考命令如下:
```shell
# mkdliso -p qcow2 -c custom/cfg_qcow2
```
命令执行完成后,制作出的新文件在 /opt/imageTailor/result/{日期} 目录下,包括 `openEuler_riscv64.qcow2`、`openEuler_riscv64.qcow2.sha256`、`fw_payload_oe_uboot.bin`。其中 `fw_payload_oe_uboot.bin` 为启动用内核。
2. 验证 ISO 镜像文件的完整性。此处假设日期为 2023-08-16-20-22。
```shell
cd /opt/imageTailor/result/2023-08-16-20-22/
sha256sum -c openEuler_riscv64.qcow2.sha256
```
回显如下,表示 ISO 镜像文件完整,ISO 制作完成。
```text
openEuler_riscv64.qcow2: OK
```
若回显如下,表示镜像不完整,说明 ISO 镜像文件完整性被破坏,需要重新制作。
```shell
openEuler_riscv64.qcow2: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match
```
### 启动系统
这里我们假设在 Linux 下启动系统。编写一个简单的 `start_vm.sh`:
```shell
#!/usr/bin/env bash
qemu-system-riscv64 \
-nographic -machine virt \
-smp 4 -m 8G \
-bios "fw_payload_oe_uboot.bin" \
-drive file="openEuler_riscv64.qcow2",format=qcow2,id=hd0 \
-object rng-random,filename=/dev/urandom,id=rng0 \
-device virtio-vga \
-device virtio-rng-device,rng=rng0 \
-device virtio-blk-device,drive=hd0 \
-device virtio-net-device,netdev=usernet \
-netdev user,id=usernet,hostfwd=tcp::12055-:22 \
-device qemu-xhci -usb -device usb-kbd -device usb-tablet
```
我们假设给 QEMU 虚拟机 4 个 CPU,8 GB 的 RAM。Guest 机器的 22 端口转发在 Host 机器的 12055 端口上。