5.11. 使用 bootc-image-builder 构建无状态 PXE 镜像
您可以使用 bootc-image-builder 工具将 bootc 容器镜像转换为带有一组工件(如 kernel、initrd 和 squashfs rootfs)的 pxe-tar-xz 镜像类型。
先决条件
- bootc 容器。
-
dracut-live和squashfs-tools软件包包含在 Containerfile 中。 -
容器镜像使用
initramfs中内置的dmsquash-live模块构建。例如,请参阅 Containerfile。 - 用于托管生成的工件的功能 TFTP 或 HTTP 服务器。
流程
创建 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构建容器镜像:
$ podman build -f ./Containerfile -t bootc-dracut运行
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 系统,而不是基于软件包的系统。
验证
在部署之前,请验证容器镜像是否已正确构建,并且包含必要的配置文件和模块。
检查您构建的容器:
$ podman run --rm -it localhost/bootc-dracut:latest /usr/bin/bash-
验证
/usr/lib/ostree/prepare-root.conf和/usr/lib/dracut/dracut.conf.d/40-pxe.conf文件是否已正确创建。 检查 initramfs 模块,以确保
dmsquash-live和ostree模块存在:$ lsinitrd --mod /usr/lib/modules//initramfs.img*
故障排除
- GRUB 菜单不可用
- 原因: EFI 二进制文件或配置文件被错误记录。
-
解决方案 :验证
grub.cfg文件是否与grubx64.efi文件位于同一个目录中。将BOOTX64.EFI、grubx64.efi和grub.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文件中被禁用。
-
原因: