Skip to content

Commit

Permalink
ostree: Use bootupd if installed by payload
Browse files Browse the repository at this point in the history
Original commit message from Colin Walters was:

The https://github.com/coreos/bootupd project was created to fill
the gap in bootloader management for ostree-based systems.

When it was created, it was just integrated into Fedora CoreOS
and derivatives; this left the Atomic Desktops (Silverblue etc.)
as unfixed, and it was never used by RHEL for Edge.

This PR is aiming to circle back and close that gap.  We
detect if bootupd is in the target root; if it is, then
we skip the regular bootloader work, and just run bootupd to
perform the installation.

The other hacks we have around the grub config are no longer
necessary in this mode.

(cherry picked from commit 8e690d5)

Related: RHEL-2250
  • Loading branch information
VladimirSlavik authored and cgwalters committed Jan 25, 2024
1 parent 6dfbab2 commit 18142c0
Show file tree
Hide file tree
Showing 4 changed files with 132 additions and 2 deletions.
31 changes: 30 additions & 1 deletion pyanaconda/modules/payloads/payload/rpm_ostree/installation.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@
from pyanaconda.core.glib import format_size_full, create_new_context, Variant, GError
from pyanaconda.core.i18n import _
from pyanaconda.core.util import execWithRedirect, mkdirChain, set_system_root
from pyanaconda.modules.common.errors.installation import PayloadInstallationError, \
BootloaderInstallationError
from pyanaconda.modules.common.task import Task
from pyanaconda.modules.common.constants.objects import DEVICE_TREE, BOOTLOADER
from pyanaconda.modules.common.constants.services import STORAGE
from pyanaconda.modules.common.structures.storage import DeviceData
from pyanaconda.modules.payloads.payload.rpm_ostree.util import have_bootupd

import gi
gi.require_version("OSTree", "1.0")
Expand Down Expand Up @@ -417,9 +420,35 @@ def name(self):
return "Configure OSTree bootloader"

def run(self):
self._move_grub_config()
if have_bootupd(self._sysroot):
self._install_bootupd()
else:
self._move_grub_config()
self._set_kargs()

def _install_bootupd(self):
bootloader = STORAGE.get_proxy(BOOTLOADER)
device_tree = STORAGE.get_proxy(DEVICE_TREE)
dev_data = DeviceData.from_structure(device_tree.GetDeviceData(bootloader.Drive))

rc = execWithRedirect(
"bootupctl",
[
"backend",
"install",
"--auto",
"--with-static-configs",
"--device",
dev_data.path,
"/",
],
root=self._sysroot
)

if rc:
raise BootloaderInstallationError(
"failed to write boot loader configuration")

def _move_grub_config(self):
"""If using GRUB2, move its config file, also with a compatibility symlink."""
boot_grub2_cfg = self._sysroot + '/boot/grub2/grub.cfg'
Expand Down
27 changes: 27 additions & 0 deletions pyanaconda/modules/payloads/payload/rpm_ostree/util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright (C) 2023 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details. You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#

import os.path
from pyanaconda.core.path import join_paths

__all__ = ["have_bootupd"]


def have_bootupd(sysroot):
"""Is bootupd/bootupctl present in sysroot?"""
return os.path.exists(join_paths(sysroot, "/usr/bin/bootupctl"))
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
ChangeOSTreeRemoteTask, ConfigureBootloader, DeployOSTreeTask, PullRemoteAndDeleteTask, \
SetSystemRootTask


def _make_config_data():
"""Create OSTree configuration data for testing
Expand Down Expand Up @@ -665,6 +664,47 @@ def test_nonbtrfs_run(self, devdata_mock, storage_mock, symlink_mock, rename_moc
root=sysroot
)

@patch("pyanaconda.modules.payloads.payload.rpm_ostree.installation.have_bootupd")
@patch("pyanaconda.modules.payloads.payload.rpm_ostree.installation.execWithRedirect")
@patch("pyanaconda.modules.payloads.payload.rpm_ostree.installation.os.rename")
@patch("pyanaconda.modules.payloads.payload.rpm_ostree.installation.os.symlink")
@patch("pyanaconda.modules.payloads.payload.rpm_ostree.installation.STORAGE")
@patch("pyanaconda.modules.payloads.payload.rpm_ostree.installation.DeviceData")
def test_bootupd_run(self, devdata_mock, storage_mock, symlink_mock, rename_mock, exec_mock,
have_bootupd_mock):
"""Test OSTree bootloader config task, bootupd"""
exec_mock.return_value = 0
have_bootupd_mock.return_value = True

proxy_mock = storage_mock.get_proxy()
proxy_mock.GetArguments.return_value = ["BOOTLOADER-ARGS"]
proxy_mock.GetFstabSpec.return_value = "FSTAB-SPEC"
proxy_mock.GetRootDevice.return_value = "device-name"
proxy_mock.Drive = "btldr-drv"
devdata_mock.from_structure.return_value.type = "something-non-btrfs-subvolume-ish"
devdata_mock.from_structure.return_value.path = "/dev/btldr-drv"

with tempfile.TemporaryDirectory() as sysroot:
task = ConfigureBootloader(sysroot)
task.run()

rename_mock.assert_not_called()
symlink_mock.assert_not_called()
assert exec_mock.call_count == 2
exec_mock.assert_has_calls([
call(
"bootupctl",
["backend", "install", "--auto", "--with-static-configs", "--device",
"/dev/btldr-drv", "/"],
root=sysroot
),
call(
"ostree",
["admin", "instutil", "set-kargs", "BOOTLOADER-ARGS", "root=FSTAB-SPEC", "rw"],
root=sysroot
)
])

@patch("pyanaconda.modules.payloads.payload.rpm_ostree.installation.execWithRedirect")
@patch("pyanaconda.modules.payloads.payload.rpm_ostree.installation.os.rename")
@patch("pyanaconda.modules.payloads.payload.rpm_ostree.installation.os.symlink")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#
# Copyright (C) 2020 Red Hat, Inc.
#
# This copyrighted material is made available to anyone wishing to use,
# modify, copy, or redistribute it subject to the terms and conditions of
# the GNU General Public License v.2, or (at your option) any later version.
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY expressed or implied, including the implied warranties of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details. You should have received a copy of the
# GNU General Public License along with this program; if not, write to the
# Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
# 02110-1301, USA. Any Red Hat trademarks that are incorporated in the
# source code or documentation are not subject to the GNU General Public
# License and may only be used or replicated with the express permission of
# Red Hat, Inc.
#
import tempfile
import unittest
from pyanaconda.core.path import join_paths, touch, make_directories

from pyanaconda.modules.payloads.payload.rpm_ostree.util import have_bootupd

class RPMOSTreeUtilTestCase(unittest.TestCase):
"""Test the RPM OSTree utils."""

def test_have_bootupd(self):
"""Test bootupd detection."""
with tempfile.TemporaryDirectory() as sysroot:
assert have_bootupd(sysroot) is False

make_directories(join_paths(sysroot, "/usr/bin"))
touch(join_paths(sysroot, "/usr/bin/bootupctl"))
assert have_bootupd(sysroot) is True

0 comments on commit 18142c0

Please sign in to comment.