From 20ed5df4daf71860d32e26be02fe6764997de3e0 Mon Sep 17 00:00:00 2001 From: Radek Vykydal Date: Thu, 29 Aug 2024 18:25:23 +0200 Subject: [PATCH] home reuse: handle bootloader partitions automagically --- .../automatic/automatic_partitioning.py | 46 +++++++++++++++---- 1 file changed, 37 insertions(+), 9 deletions(-) diff --git a/pyanaconda/modules/storage/partitioning/automatic/automatic_partitioning.py b/pyanaconda/modules/storage/partitioning/automatic/automatic_partitioning.py index c713ae1b0c6..ede0116b268 100644 --- a/pyanaconda/modules/storage/partitioning/automatic/automatic_partitioning.py +++ b/pyanaconda/modules/storage/partitioning/automatic/automatic_partitioning.py @@ -31,6 +31,7 @@ from pyanaconda.modules.storage.partitioning.automatic.utils import get_candidate_disks, \ schedule_implicit_partitions, schedule_volumes, schedule_partitions, get_pbkdf_args, \ get_default_partitioning, get_part_spec, get_disks_for_implicit_partitions +from pyanaconda.modules.storage.platform import platform from pyanaconda.core.storage import suggest_swap_size @@ -65,15 +66,9 @@ def _get_initialization_config(self): def _get_mountpoint_device(self, storage, mountpoint, required=True): devices = [] - # TODO add support for EFI - if mountpoint == "biosboot": - for device in storage.devices: - if device.format.type == "biosboot": - devices.append(device) - else: - for root in storage.roots: - if mountpoint in root.mounts: - devices.append(root.mounts[mountpoint]) + for root in storage.roots: + if mountpoint in root.mounts: + devices.append(root.mounts[mountpoint]) if len(devices) > 1: raise StorageError(_("Multiple devices found for mountpoint '{}': {}") .format(mountpoint, @@ -111,6 +106,38 @@ def _remove_mountpoint(self, storage, mountpoint): else: log.debug("DDDDD device to be removed for mountpoint %s not found", mountpoint) + def _remove_bootloader_partitions(self, storage, required=True): + log.debug("DDDDD platform.partitions %s", platform.partitions) + + bootloader_types = ["efi", "biosboot", "appleboot", "prepboot"] + bootloader_parts = [part for part in platform.partitions if part.fstype in bootloader_types] + if len(bootloader_parts) > 1: + raise StorageError(_("Multiple bootloader partitions required: %s"), bootloader_parts) + if not bootloader_parts: + log.debug("No bootloader partition required") + return False + part_type = bootloader_parts[0].fstype + + devices = [] + for device in storage.devices: + if device.format.type == part_type: + devices.append(device) + if len(devices) > 1: + raise StorageError(_("Multiple devices found for bootloader partition '{}': {}") + .format(part_type, + ", ".join([device.name for device in devices]))) + if not devices: + if required: + raise StorageError(_("No devices found for bootloader partition '{}'") + .format(part_type)) + else: + log.debug(_("No devices found for bootloader partition '{}'"), part_type) + return False + device = devices[0] + log.debug("DDDDD remove device %s for bootloader partition %s", device, part_type) + destroy_device(storage, device) + return True + def _clear_partitions(self, storage): super()._clear_partitions(storage) @@ -125,6 +152,7 @@ def _clear_partitions(self, storage): # check but also here? # TODO maybe move to _configure_partitioning? Seems safer here. + self._remove_bootloader_partitions(storage) for mountpoint in self._request.removed_mount_points: self._remove_mountpoint(storage, mountpoint) for mountpoint in self._request.erased_mount_points: