Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify results from partitionTargetDisk #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 16 additions & 14 deletions backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,22 +527,24 @@ def configureNTP(mounts, ntp_config_method, ntp_servers):
def partitionTargetDisk(disk, existing, preserve_first_partition, create_sr_part):
logger.log("Installer booted in %s mode" % ("UEFI" if constants.UEFI_INSTALLER else "legacy"))

(PRIMARY, BACKUP, STORAGE, BOOT, LOGS, SWAP) = list(range(6))

primary_part = 1
if existing:
# upgrade, use existing partitioning scheme
tool = PartitionTool(existing.primary_disk)

primary_part = tool.partitionNumber(existing.root_device)

part_nums = list(range(primary_part, primary_part+6))

# Determine target install's boot mode and boot partition number
target_boot_mode = TARGET_BOOT_MODE_LEGACY
if existing.boot_device:
boot_partnum = tool.partitionNumber(existing.boot_device)
boot_part = tool.getPartition(boot_partnum)
part_nums[BOOT] = tool.partitionNumber(existing.boot_device)
boot_part = tool.getPartition(part_nums[BOOT])
if 'id' in boot_part and boot_part['id'] == GPTPartitionTool.ID_EFI_BOOT:
target_boot_mode = TARGET_BOOT_MODE_UEFI
else:
boot_partnum = primary_part + 3

if (target_boot_mode == TARGET_BOOT_MODE_UEFI and not constants.UEFI_INSTALLER) or \
(target_boot_mode == TARGET_BOOT_MODE_LEGACY and constants.UEFI_INSTALLER):
Expand All @@ -552,11 +554,10 @@ def partitionTargetDisk(disk, existing, preserve_first_partition, create_sr_part
logger.log("Upgrading, target_boot_mode: %s" % target_boot_mode)

# Return install mode and numbers of primary, backup, SR, boot, log and swap partitions
storage_partition = tool.getPartition(primary_part+2)
if storage_partition:
return (target_boot_mode, primary_part, primary_part+1, primary_part+2, boot_partnum, primary_part+4, primary_part+5)
else:
return (target_boot_mode, primary_part, primary_part+1, 0, boot_partnum, primary_part+4, primary_part+5)
storage_partition = tool.getPartition(part_nums[STORAGE])
if not storage_partition:
part_nums[STORAGE] = 0
return tuple([target_boot_mode] + part_nums)

tool = PartitionTool(disk)

Expand All @@ -576,17 +577,18 @@ def partitionTargetDisk(disk, existing, preserve_first_partition, create_sr_part
if primary_part > 2:
raise RuntimeError("Installer only supports a single Utility Partition at partition 1, but found Utility Partitions at %s" % str(utilparts))

sr_part = -1
if create_sr_part:
sr_part = primary_part+2
part_nums = list(range(primary_part, primary_part+6))

if not create_sr_part:
part_nums[STORAGE] = -1

boot_part = max(primary_part + 1, sr_part) + 1
part_nums[BOOT] = max(primary_part + 1, part_nums[STORAGE]) + 1

target_boot_mode = TARGET_BOOT_MODE_UEFI if constants.UEFI_INSTALLER else TARGET_BOOT_MODE_LEGACY

logger.log("Fresh install, target_boot_mode: %s" % target_boot_mode)

return (target_boot_mode, primary_part, primary_part + 1, sr_part, boot_part, primary_part + 4, primary_part + 5)
return tuple([target_boot_mode] + part_nums)

def removeBlockingVGs(disks):
for vg in diskutil.findProblematicVGs(disks):
Expand Down