Skip to content

Commit

Permalink
home reuse: remove bootloader partitions implicitly
Browse files Browse the repository at this point in the history
  • Loading branch information
rvykydal committed Sep 3, 2024
1 parent 372947c commit 47168d9
Showing 1 changed file with 37 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)

Expand All @@ -122,6 +149,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:
Expand Down

0 comments on commit 47168d9

Please sign in to comment.