向主机系统添加操作系统扩展

出于安全性和可维护性的考虑,Fedora CoreOS使基本镜像尽可能简单和小巧。这就是为什么您通常应该更喜欢使用 podman 容器覆盖分层软件。

但是,在某些情况下,有必要将软件添加到基本操作系统本身。例如,驱动程序或VPN软件是潜在的候选,因为它们更难包装。

要做到这一点,您可以使用 rpm-ostree install 。将这些包视为“扩展”:它们扩展了基本操作系统的功能,而不是为用户应用程序提供运行时。这就是说,对于可以实际安装的包没有限制。默认情况下,程序包从 Fedora储存库

要开始包的分层,您需要编写一个系统d单元来执行 rpm-ostree 命令来安装所需的程序包。 默认情况下,使用 rpm-ostree install ,更改将排队等待下一次引导。这个 -A/--apply-live 选项可用于实时应用更改*并使其持久化。

示例:对vim进行分层并将其设置为默认编辑器

Fedora CoreOS包括这两种功能 nanovi 作为文本编辑者,将前者设置为默认设置(请参见相应的 更换软呢帽 )。

此示例说明如何安装功能齐全的 vim 以及如何通过在中设置所需的配置来将其设置为所有用户的默认设置 /etc/profile.d/

在未来,我们将有一种更有利于Ignition的方法来做到这一点,并提供更强有力的保证。请参阅上游问题 Butane#81Fedora-CoreOS-追踪器#681 以获取更多信息。
variant: fcos
version: 1.4.0
systemd:
  units:
    # Installing vim as a layered package with rpm-ostree
    - name: rpm-ostree-install-vim.service
      enabled: true
      contents: |
        [Unit]
        Description=Layer vim with rpm-ostree
        Wants=network-online.target
        After=network-online.target
        # We run before `zincati.service` to avoid conflicting rpm-ostree
        # transactions.
        Before=zincati.service
        ConditionPathExists=!/var/lib/%N.stamp

        [Service]
        Type=oneshot
        RemainAfterExit=yes
        # `--allow-inactive` ensures that rpm-ostree does not return an error
        # if the package is already installed. This is useful if the package is
        # added to the root image in a future Fedora CoreOS release as it will
        # prevent the service from failing.
        ExecStart=/usr/bin/rpm-ostree install --apply-live --allow-inactive vim
        ExecStart=/bin/touch /var/lib/%N.stamp

        [Install]
        WantedBy=multi-user.target
storage:
  files:
    # Set vim as default editor
    # We use `zz-` as prefix to make sure this is processed last in order to
    # override any previously set defaults.
    - path: /etc/profile.d/zz-default-editor.sh
      overwrite: true
      contents:
        inline: |
          export EDITOR=vim