6.8. 使用 to-filesystem 的高级安装
bootc install 包含两个子命令:bootc install to-disk 和 bootc 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
-
6.8.1. 使用 bootc install to-existing-root 复制链接链接已复制到粘贴板!
bootc install to-existing-root 是 install 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# 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-rootCopy to Clipboard Copied! Toggle word wrap Toggle overflow 这个命令删除
/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# 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_keysCopy to Clipboard Copied! Toggle word wrap Toggle overflow