搜索

4.8. 使用 to-filesystem 的高级安装

download PDF

bootc install 包含两个子命令:bootc install to-diskbootc install to-filesystem

  • bootc-install-to-filesystem 执行到目标文件系统的安装。
  • bootc install to-disk 子命令包含一组固执己见的较低级别的工具,您可以单独调用它们。命令由以下工具组成:

    • mkfs.$fs /dev/disk
    • mount /dev/disk /mnt
    • bootc install to-filesystem --karg=root=UUID=<uuid of /mnt> --imgref $self /mnt

4.8.1. 使用 bootc install to-existing-root

bootc install to-existing-rootinstall to-filesystem 的一种变体。您可以使用它来将现有系统转换为目标容器镜像。

警告

这个转换删除了 /boot/boot/efi 分区,并可删除现有 Linux 安装。转换过程重复使用文件系统,即使已保留了用户数据,系统也不再以软件包模式引导。

先决条件

  • 您必须具有 root 权限才能完成这个流程。
  • 您必须匹配主机环境和目标容器版本,例如,如果您的主机是 RHEL 9 主机,则您必须有一个 RHEL 9 容器。使用 btrfs 在 Fedora 主机上安装 RHEL 容器,因为 RHEL 内核不支持该文件系统。

流程

  • 运行以下命令将现有系统转换为目标容器镜像。使用 -v /:/target 选项传递目标 rootfs

    # podman run --rm --privileged -v /dev:/dev -v /var/lib/containers:/var/lib/containers -v /:/target \
                --pid=host --security-opt label=type:unconfined_t \
                <image> \
                bootc install to-existing-root

    这个命令删除 /boot 中的数据,但现有操作系统中的所有其他内容不会被自动删除。这很有用,因为新镜像可以自动从以前的主机系统导入数据。因此,在 /sysroot 中后续重新启动后,容器镜像、数据库、用户主目录数据、/etc 中的配置文件都可用。

    您还可以通过添加 --root-ssh-authorized-keys /target/root/.ssh/authorized_keys 来使用 --root-ssh-authorized-keys 标志继承 root 用户 SSH 密钥。例如:

    # podman run --rm --privileged -v /dev:/dev -v /var/lib/containers:/var/lib/containers -v /:/target \
                --pid=host --security-opt label=type:unconfined_t \
                <image> \
                bootc install to-existing-root --root-ssh-authorized-keys /target/root/.ssh/authorized_keys
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

© 2024 Red Hat, Inc.