override replace --experimental
覆盖替换 --实验性

To improve the experience when overriding packages directly from a RPM repository, rpm-ostree has experimental support for fetching RPMs and overriding them. Full support for this feature is tracked in #1265.
为了改善直接从 RPM 存储库覆盖软件包时的体验,rpm-ostree 支持实验性地获取 RPM 并覆盖它们。对此功能的完整支持在#1265 中跟踪。

Overriding packages with the versions from a given repo
使用给定存储库中的版本覆盖软件包

For this example, we will replace the kernel shipped as part of the base image in Fedora CoreOS with the one provided by the Vanilla Kernel Repositories. This is something useful for example if you want to try reproducing a bug on a recent vanilla Linux kernel to make sure this is not something coming from a Fedora specific patch.
对于这个示例,我们将使用 Vanilla Kernel 仓库提供的内核替换 Fedora CoreOS 基础镜像中提供的内核。例如,如果您想尝试在最新的 Vanilla Linux 内核上重现错误,以确保这不是来自 Fedora 特定补丁的问题,这将非常有用。

First, we setup the custom RPM repository, in this case for the mainline-wo-mergew repo of the Vanilla Kernel repositories:
首先,我们设置自定义的 RPM 仓库,这里是为 Vanilla Kernel 仓库的 mainline-wo-mergew 仓库做准备:

$ curl -s https://copr.fedorainfracloud.org/coprs/g/kernel-vanilla/mainline-wo-mergew/repo/fedora-rawhide/group_kernel-vanilla-mainline-wo-mergew-fedora-rawhide.repo | sudo tee /etc/yum.repos.d/kernel-vanilla-mainline-wo-mergew.repo

Then we ask rpm-ostree to override the current kernel package with the ones from the repository:
然后,我们要求 rpm-ostree 使用仓库中的内核包覆盖当前的内核包:

$ sudo rpm-ostree override replace --experimental --freeze --from repo='copr:copr.fedorainfracloud.org:group_kernel-vanilla:mainline-wo-mergew' kernel kernel-core kernel-modules kernel-modules-core kernel-modules-extra
Inactive base replacements:
  kernel-modules-core-6.2.0-0.rc7.20230208gt0983f6bf.251.vanilla.fc37.x86_64
Checking out tree 8c16620... done
Enabled rpm-md repositories: fedora-cisco-openh264 fedora-modular updates-modular updates fedora copr:copr.fedorainfracloud.org:group_kernel-vanilla:next copr:copr.fedorainfracloud.org:group_kernel-vanilla:mainline-wo-mergew coprdep:copr.fedorainfracloud.org:group_kernel-vanilla:fedora coprdep:copr.fedorainfracloud.org:group_kernel-vanilla:stable-rc coprdep:copr.fedorainfracloud.org:group_kernel-vanilla:stable updates-archive
Importing rpm-md... done
rpm-md repo 'fedora-cisco-openh264' (cached); generated: 2022-10-06T11:01:40Z solvables: 4
rpm-md repo 'fedora-modular' (cached); generated: 2022-11-05T07:58:03Z solvables: 1454
rpm-md repo 'updates-modular' (cached); generated: 2023-01-03T01:27:52Z solvables: 1464
rpm-md repo 'updates' (cached); generated: 2023-02-10T00:30:00Z solvables: 18414
rpm-md repo 'fedora' (cached); generated: 2022-11-05T08:04:38Z solvables: 66822
rpm-md repo 'copr:copr.fedorainfracloud.org:group_kernel-vanilla:next' (cached); generated: 2023-02-08T20:43:20Z solvables: 99
rpm-md repo 'copr:copr.fedorainfracloud.org:group_kernel-vanilla:mainline-wo-mergew' (cached); generated: 2023-02-10T03:54:23Z solvables: 132
rpm-md repo 'coprdep:copr.fedorainfracloud.org:group_kernel-vanilla:fedora' (cached); generated: 2023-02-09T12:51:18Z solvables: 30
rpm-md repo 'coprdep:copr.fedorainfracloud.org:group_kernel-vanilla:stable-rc' (cached); generated: 2023-02-07T15:56:26Z solvables: 40
rpm-md repo 'coprdep:copr.fedorainfracloud.org:group_kernel-vanilla:stable' (cached); generated: 2023-01-21T14:43:13Z solvables: 0
rpm-md repo 'updates-archive' (cached); generated: 2023-02-10T00:59:42Z solvables: 23391
Resolving dependencies... done
Will download: 1 package (38,7 MB)
Downloading from 'copr:copr.fedorainfracloud.org:group_kernel-vanilla:mainline-wo-mergew'... done
Importing packages... done
Relabeling... done
Applying 4 overrides
Processing packages... done
Running pre scripts... done
Running post scripts... done
Running posttrans scripts... done
Writing rpmdb... done
Generating initramfs... done
Writing OSTree commit... done
Staging deployment... done
Freed: 191,3 MB (pkgcache branches: 0)
Upgraded:
  kernel 6.1.8-200.fc37 -> 6.2.0-0.rc7.20230208gt0983f6bf.251.vanilla.fc37
  kernel-core 6.1.8-200.fc37 -> 6.2.0-0.rc7.20230208gt0983f6bf.251.vanilla.fc37
  kernel-modules 6.1.8-200.fc37 -> 6.2.0-0.rc7.20230208gt0983f6bf.251.vanilla.fc37
  kernel-modules-extra 6.1.8-200.fc37 -> 6.2.0-0.rc7.20230208gt0983f6bf.251.vanilla.fc37
Added:
  kernel-modules-core-6.2.0-0.rc7.20230208gt0983f6bf.251.vanilla.fc37.x86_64
Use "rpm-ostree override reset" to undo overrides
Run "systemctl reboot" to start a reboot

$ rpm-ostree status
State: idle
...
Deployments:
  fedora:fedora/37/x86_64/silverblue
                  Version: 37.20230201.0 (2023-02-01T02:01:44Z)
               BaseCommit: 8c16620566268918906174992bfacfe41e9f47dd433393fa95e3439736961791
             GPGSignature: Valid signature by ACB5EE4E831C74BB7C168D27F55AD3FB5323552A
                     Diff: 4 upgraded, 1 added
           LocalOverrides: kernel-core kernel-modules kernel kernel-modules-extra 6.1.8-200.fc37 -> 6.2.0-0.rc7.20230208gt0983f6bf.251.vanilla.fc37
...

In this second example, we will override the podman rpm package with the version of the package used in the Fedora updates-testing repository. The repository can be found in /etc/yum.repos.d/fedora-updates-testing.repo but is not enabled by default:
在这个第二个例子中,我们将使用 Fedora updates-testing 仓库中使用的软件包版本覆盖 podman rpm 软件包。该仓库可以在 /etc/yum.repos.d/fedora-updates-testing.repo 找到,但默认情况下未启用:

[updates-testing]
name=Fedora $releasever - $basearch - Test Updates
#baseurl=http://download.example/pub/fedora/linux/updates/testing/$releasever/Everything/$basearch/
metalink=https://mirrors.fedoraproject.org/metalink?repo=updates-testing-f$releasever&arch=$basearch
enabled=0
countme=1
repo_gpgcheck=0
type=rpm
gpgcheck=1
metadata_expire=6h
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-$releasever-$basearch
skip_if_unavailable=False

[...]

To enable the repository, we will use the sed command to set the first occurrence of the enabled flag to true:
要启用该仓库,我们将使用 sed 命令将第一个出现的 enabled 标志设置为 true:

$ sudo sed -i '0,/enabled=0/s//enabled=1/' /etc/yum.repos.d/fedora-updates-testing.repo
$ sudo rpm-ostree override replace podman --experimental --from repo='updates-testing'
Checking out tree e88367e... done
Enabled rpm-md repositories: fedora-cisco-openh264 fedora-modular updates-modular updates fedora updates-repo updates-archive
Importing rpm-md... done
rpm-md repo 'fedora-cisco-openh264' (cached); generated: 2023-03-14T10:56:46Z solvables: 4
rpm-md repo 'fedora-modular' (cached); generated: 2023-04-13T20:30:47Z solvables: 1082
rpm-md repo 'updates-modular' (cached); generated: 2018-02-20T19:18:14Z solvables: 0
rpm-md repo 'updates' (cached); generated: 2023-06-01T03:25:51Z solvables: 13930
rpm-md repo 'fedora' (cached); generated: 2023-04-13T20:37:10Z solvables: 69222
rpm-md repo 'updates-repo' (cached); generated: 2023-06-01T03:05:18Z solvables: 13082
rpm-md repo 'updates-archive' (cached); generated: 2023-06-01T03:49:37Z solvables: 14720
Resolving dependencies... done
Will download: 1 package (15.2 MB)
Downloading from 'updates-repo'... done
Importing packages... done
Applying 1 override
Processing packages... done
Running pre scripts... done
Running post scripts... done
Running posttrans scripts... done
Writing rpmdb... done
Writing OSTree commit... done
Staging deployment... done
Freed: 2.1 MB (pkgcache branches: 0)
Upgraded:
  podman 5:4.5.0-1.fc38 -> 5:4.5.1-1.fc38
Run "systemctl reboot" to start a reboot

Running the rpm-ostree status command shows that the podman package has undergone a remote override using the updates-repo repository we previously defined.
运行 rpm-ostree status 命令显示 podman 软件包已经通过我们之前定义的 updates-repo 仓库进行了远程覆盖。

$ rpm-ostree status
State: idle
Deployments:
  fedora:fedora/x86_64/coreos/testing-devel
                  Version: 38.20230601.dev.0 (2023-06-01T18:17:16Z)
               BaseCommit: e88367e123c1858979bccb19ead16a3f353cd5fdfcf014218f25a5fd28cab611
             GPGSignature: (unsigned)
                     Diff: 1 upgraded
          RemoteOverrides: repo=updates-repo
                           └─ podman 5:4.5.0-1.fc38 -> 5:4.5.1-1.fc38

Rolling back 回滚

You can rollback to the previous deployment:
您可以回滚到上一个部署:

$ rpm-ostree rollback

or reset the overrides with:
或者使用以下命令重置覆盖项:

$ rpm-ostree override reset kernel kernel-core kernel-modules kernel-modules-core kernel-modules-extra 

or reset all overrides:
或重置所有覆盖:

$ rpm-ostree override reset --all