5.12. 在离线和 air-gapped 环境中构建 bootc 镜像
您可以在不连接到互联网或红帽内容交付网络的情况下构建引导容器镜像。使用本地镜像 registry 和 RPM 存储库,然后将容器镜像转换为您选择的虚拟机格式,如 原始、AMI 或 ISO。
使用断开连接的基础架构需要将构建配置为从本地 registry 的源容器镜像和 RPM 内容,例如:
- 托管在私有 Web 服务器或 Red Hat Satellite 上的私有容器注册表和 RPM 存储库。
- 从本地存储库中拉取基础镜像,而不是从互联网拉取。
- 您的 Containerfile 必须指向基础镜像的本地镜像 registry,并使用本地 HTTP 服务器进行 RPM 内容。
使用 bootc-image-builder 命令将容器转换为磁盘镜像后,您可以在 air-gapped 环境中部署基于 RHEL 的可引导系统。
重要
在您要构建的容器镜像中定义存储库配置。您不能将主机机器的存储库设置与 bootc-image-builder 搭配使用。相反,您必须在容器镜像中直接提供存储库配置。
先决条件
- 在目标硬件上部署的 Red Hat Enterprise Linux 10 正在运行的 RHEL 系统。
-
container-tools元数据软件包已安装。 - 访问 registry 或本地存储的容器。
流程
创建 Containerfile。例如:
# Base image to point to your internal registry FROM example.com:1234/rhel10/rhel-bootc:10.2 # Configure the local repo to use the files already present in the image # Assuming the repo data is located at /etc/pki/repos or similar inside the image RUN echo -e "[local-baseos]\n\ name=Local RHEL 10 BaseOS\n\ baseurl=file:///path/to/repo/in/image/BaseOS\n\ enabled=1\n\ gpgcheck=0" > /etc/yum.repos.d/local.repo # Install your required packages using the local file source RUN dnf install -y firewalld && \ dnf clean all # Ensure the kernel and bootloader are present # In air-gapped bootc, BIB often fails because it expects to download these. # Pre-installing them ensures they are part of the 'bootc' transition. RUN dnf install -y kernel-bootc anaconda-dracut-modules && dnf clean all-
使用
bootc-image-builder工具将 Containerfile 转换为可引导格式,如 ISO、原始、QCOW2。请参阅使用 bootc-image-builder 创建与引导兼容的基本磁盘镜像。
故障排除
如果已经缓存了软件包,原始 磁盘镜像可能会成功。如果您构建 ISO,它可能会触发 osbuild-depsolve-dnf 依赖项解决过程。
如果您的 .repo 文件包含 gpgkey URL,bootc-image-builder 工具会在清单生成阶段尝试获取 gpg 密钥。在 air-gapped 环境中,检查以下信息:
-
确保
gpgkey参数指向可访问的本地 HTTP 服务器或镜像中已存在的文件路径,如/etc/pki/rpm-gpg/。 -
即使
dnf install命令在容器构建期间工作,因为密钥已经缓存或跳过,ISO 创建过程也可以重新验证这些密钥。不正确的 URL 会导致错误,如GPGKeyReadError或404 Not Found。 -
要解决这些问题,请在本地存储 GPG 密钥:对于 GPG 密钥引用远程 URL,请在容器镜像中包含密钥,并通过您的
.repo文件中的file:/引用它们。 -
如果您遇到
无法构建清单错误,请仔细检查容器/etc/yum.repos.d/中每个存储库 URL 和 GPG URL 均可从运行bootc-image-builder的网络访问。
后续步骤
- 您可以部署镜像。请参阅 在离线和 air-gapped 环境中部署镜像模式更新。