6.8. 使用 bootc-image-builder 在生成的磁盘镜像中注入配置


您可以使用 构建配置 (即 .toml )或 .json 文件为生成的镜像注入自定义镜像。'build config 文件映射到容器目录到 /config.toml。以下示例演示了如何将用户添加到生成的磁盘镜像中:

流程

  1. 创建 ./config.toml。以下示例演示了如何将用户添加到磁盘镜像中。

    [[customizations.user]]
    name = "user"
    password = "pass"
    key = "ssh-rsa AAA ... user@email.com"
    groups = ["wheel"]
    Copy to Clipboard Toggle word wrap
    • 名称 - 必选.用户的名称。
    • 密码 - 不强制要求。非加密密码.
    • (不是强制)公共 SSH 密钥内容。
    • (不是强制)将用户添加到的组数组。
  2. 运行 bootc-image-builder 并通过以下参数,包括 ./config.toml

    $ sudo podman run \
        --rm \
        -it \
        --privileged \
        --pull=newer \
        --security-opt label=type:unconfined_t \
        -v $(pwd)/config.toml:/config.toml \
        -v $(pwd)/output:/output \
        registry.redhat.io/rhel10/bootc-image-builder:latest \
        --type qcow2 \
        --config config.toml \
        quay.io/<namespace>/<image>:<tag>
    Copy to Clipboard Toggle word wrap
  3. 启动虚拟机,例如使用 virt-install

    $ sudo virt-install \
      --name bootc \
      --memory 4096 \
      --vcpus 2 \
      --disk qcow2/disk.qcow2 \
      --import \
      --os-variant rhel10
    Copy to Clipboard Toggle word wrap

验证

  • 使用 SSH 访问系统:

    # ssh -i /<path_to_private_ssh-key> <user1>_@_<ip-address>
    Copy to Clipboard Toggle word wrap

后续步骤

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat