5.11. 使用 bootc-image-builder 构建无状态 PXE 镜像


您可以使用 bootc-image-builder 工具将 bootc 容器镜像转换为带有一组工件(如 kernel、initrd 和 squashfs rootfs)的 pxe-tar-xz 镜像类型。

先决条件

  • bootc 容器。
  • dracut-livesquashfs-tools 软件包包含在 Containerfile 中。
  • 容器镜像使用 initramfs 中内置的 dmsquash-live 模块构建。例如,请参阅 Containerfile。
  • 用于托管生成的工件的功能 TFTP 或 HTTP 服务器。

流程

  1. 创建 Containerfile :

    FROM quay.io/<namespace>/<image>:latest
    RUN dnf -y install dracut-live squashfs-tools && dnf clean all
    # Override using composefs for ostree (it is incompatible with the squashfs rootfs)
    RUN cat <<EOF > /usr/lib/ostree/prepare-root.conf
    [composefs]
    enabled = no
    [sysroot]
    readonly = true
    EOF
    # Include the dmsquash-live module in the initramfs
    RUN cat <<EOF > /usr/lib/dracut/dracut.conf.d/40-pxe.conf
    compress="xz"
    add_dracutmodules+=" qemu qemu-net livenet dmsquash-live "
    early_microcode="no"
    EOF
    
    # Rebuild the initrd
    RUN set -xe; kver=$(ls /usr/lib/modules); env DRACUT_NO_XATTR=1 dracut -vf /usr/lib/modules/$kver/initramfs.img "$kver"
    
    # Mask services that aren't compatible with running from the rootfs
    RUN systemctl mask bootc-generic-growpart.service bootc-publish-rhsm-facts.service
    RUN bootc container lint
  2. 构建容器镜像:

    $ podman build -f ./Containerfile -t bootc-dracut
  3. 运行 bootc-image-builder 以创建 tar 文件:

    $ mkdir -p ./output
    $ sudo podman run \
        --rm \
        -it \
        --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 pxe-tar-xz \
        --local \
        localhost/bootc-dracut:latest

    如果您的 Containerfile 位于远程系统中,请将 localhost/bootc-dracut:latest 替换为正确的 URL。

    生成的 tar 文件与基于软件包的 pxe-tar-xz 镜像相同。唯一的区别是 grub.cfg 文件还在内核命令行中增加了 ostree=…​,而 rootfs.img 文件是一个 OSTree 系统,而不是基于软件包的系统。

验证

在部署之前,请验证容器镜像是否已正确构建,并且包含必要的配置文件和模块。

  1. 检查您构建的容器:

    $ podman run --rm -it localhost/bootc-dracut:latest /usr/bin/bash
  2. 验证 /usr/lib/ostree/prepare-root.conf/usr/lib/dracut/dracut.conf.d/40-pxe.conf 文件是否已正确创建。
  3. 检查 initramfs 模块,以确保 dmsquash-liveostree 模块存在:

    $ lsinitrd --mod /usr/lib/modules//initramfs.img*

故障排除

GRUB 菜单不可用
  • 原因: EFI 二进制文件或配置文件被错误记录。
  • 解决方案 :验证 grub.cfg 文件是否与 grubx64.efi 文件位于同一个目录中。将 BOOTX64.EFIgrubx64.efigrub.cfg 文件放在 TFTP 服务器所指向的目录的根目录下。
rootfs.img 文件无法加载
  • 原因 :[FAILED] Failed to start initrd-switch-root.service - Switch Root.
  • 解决方案 :验证 initramfs 是否包含 dmsquash-live 模块。
  • 原因: curl 处于尝试下载 rootfs.img 文件的循环中: Warning: failed to download live image: error 253
  • 解决方案 :确保 rootfs.img 文件位于 grub.cfg 文件中的 root=live:…​ 指定的位置。检查 HTTP 服务器日志,以验证请求路径是否与预期位置匹配。
OSTree root 无法挂载
  • 原因: ostree-prepare-root: Couldn't find specified OSTree root
  • 解析:确保 grub.cfg 文件与 rootfs.img 文件匹配,即它们源自同一 tar 文件。grub.cfg 文件中的 ostree=…​ 条目必须指向 rootfs.img 文件中的路径。当 rootfs.img 文件与 grub.cfg 文件不匹配时,通常会发生不匹配,因为构建过程从 OSTree 目录中设定这个 UUID。
  • 原因: Failed to mount composefs: composefs: failed to mount: Input/output error
  • 解决方案 :验证 composefs 是否在 prepare-root.conf 文件中被禁用。
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

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

让开源更具包容性

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

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部