4.4. 使用 bootc-image-builder 创建 QEMU 磁盘镜像
对于您要在其上运行命令的架构,将 RHEL bootc 镜像构建到 QEMU (QCOW2)镜像中。
RHEL 基础镜像不包括默认用户。另外,您可以使用 --config 选项注入用户配置,以运行 bootc-image-builder 容器。或者,您可以使用 cloud-init 配置基础镜像,以便在第一次引导时注入用户和 SSH 密钥。请参阅 用户和组配置 - 使用 cloud-init 注入用户和 SSH 密钥。
先决条件
- 您已在主机机器上安装了 Podman。
-
您有运行
bootc-image-builder工具的 root 访问权限,并在--privileged模式下运行容器,以构建镜像。 - 在系统根容器注册中心中有基础 bootc 容器镜像。
流程
可选:创建一个
config.toml来配置用户访问,例如:[[customizations.user]] name = "user" password = "pass" key = "ssh-rsa AAA ... user@email.com" groups = ["wheel"]运行
bootc-image-builder。另外,如果您想要使用用户访问配置,请将config.toml作为参数传递。以下示例创建了一个公共 QEMU 磁盘镜像(QCOW2)。要构建公共镜像,您在远程、可公开访问的注册中心(如
registry.redhat.io/rhel10/bootc-image-builder:latest)中有一个可用的容器镜像。镜像可供下载和使用,而无需特殊凭据。$ sudo podman run \ --rm \ --privileged \ --pull=newer \ --security-opt label=type:unconfined_t \ -v ./config.toml:/config.toml:ro \ -v ./output:/output \ registry.redhat.io/rhel10/bootc-image-builder:latest \ --type qcow2 \ --config /config.toml \ quay.io/<namespace>/<image>:<tag>这个示例从本地容器创建一个私有 QEMU 磁盘镜像(QCOW2)。要构建私有镜像,则必须在本地机器上有一个容器镜像,该容器镜像在公共注册中心中不提供。本地镜像可以是一个您使用 Containerfile 构建的镜像、一个您从私有的、访问控制的、需要登录的注册中心拉取的镜像,或一个从 tar 文件加载的镜像。bootc-image-builder 从本地 Podman
/var/lib/containers/storage存储中查找和使用源镜像,该镜像被挂载到构建器容器中。$ sudo podman run \ --rm \ -it \ --privileged \ --pull=newer \ --security-opt label=type:unconfined_t \ -v ./config.toml:/config.toml:ro \ -v ./output:/output \ -v /var/lib/containers/storage:/var/lib/containers/storage \ registry.redhat.io/rhel10/bootc-image-builder:latest \ --type qcow2 \ --config /config.toml \ quay.io/<namespace>/<image>:<tag>您可以在 output 文件夹中找到
.qcow2镜像。