Fix GPT end alignment (#2210)

This commit is contained in:
codefiles 2023-11-20 06:58:09 -05:00 committed by GitHub
parent f876ddc68e
commit f16af43949
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 39 additions and 22 deletions

View File

@ -176,9 +176,9 @@ def select_disk_config(
return None return None
def _boot_partition(sector_size: disk.SectorSize) -> disk.PartitionModification: def _boot_partition(sector_size: disk.SectorSize, using_gpt: bool) -> disk.PartitionModification:
flags = [disk.PartitionFlag.Boot] flags = [disk.PartitionFlag.Boot]
if SysInfo.has_uefi(): if using_gpt:
start = disk.Size(1, disk.Unit.MiB, sector_size) start = disk.Size(1, disk.Unit.MiB, sector_size)
size = disk.Size(512, disk.Unit.MiB, sector_size) size = disk.Size(512, disk.Unit.MiB, sector_size)
flags.append(disk.PartitionFlag.ESP) flags.append(disk.PartitionFlag.ESP)
@ -242,6 +242,8 @@ def suggest_single_disk_layout(
device_modification = disk.DeviceModification(device, wipe=True) device_modification = disk.DeviceModification(device, wipe=True)
using_gpt = SysInfo.has_uefi()
# Used for reference: https://wiki.archlinux.org/title/partitioning # Used for reference: https://wiki.archlinux.org/title/partitioning
# 2 MiB is unallocated for GRUB on BIOS. Potentially unneeded for other bootloaders? # 2 MiB is unallocated for GRUB on BIOS. Potentially unneeded for other bootloaders?
@ -253,7 +255,7 @@ def suggest_single_disk_layout(
# Also re-align the start to 1MiB since we don't need the first sectors # Also re-align the start to 1MiB since we don't need the first sectors
# like we do in MBR layouts where the boot loader is installed traditionally. # like we do in MBR layouts where the boot loader is installed traditionally.
boot_partition = _boot_partition(sector_size) boot_partition = _boot_partition(sector_size, using_gpt)
device_modification.add_partition(boot_partition) device_modification.add_partition(boot_partition)
if not using_subvolumes: if not using_subvolumes:
@ -267,20 +269,25 @@ def suggest_single_disk_layout(
else: else:
using_home_partition = False using_home_partition = False
align_buffer = disk.Size(1, disk.Unit.MiB, sector_size)
# root partition # root partition
start = disk.Size(513, disk.Unit.MiB, sector_size) if SysInfo.has_uefi() else disk.Size(206, disk.Unit.MiB, sector_size) root_start = boot_partition.start + boot_partition.length
# Set a size for / (/root) # Set a size for / (/root)
if using_subvolumes or device_size_gib < min_size_to_allow_home_part or not using_home_partition: if using_subvolumes or device_size_gib < min_size_to_allow_home_part or not using_home_partition:
length = device.device_info.total_size - start root_length = device.device_info.total_size - root_start
else: else:
length = min(device.device_info.total_size, root_partition_size) root_length = min(device.device_info.total_size, root_partition_size)
if using_gpt and not using_home_partition:
root_length -= align_buffer
root_partition = disk.PartitionModification( root_partition = disk.PartitionModification(
status=disk.ModificationStatus.Create, status=disk.ModificationStatus.Create,
type=disk.PartitionType.Primary, type=disk.PartitionType.Primary,
start=start, start=root_start,
length=length, length=root_length,
mountpoint=Path('/') if not using_subvolumes else None, mountpoint=Path('/') if not using_subvolumes else None,
fs_type=filesystem_type, fs_type=filesystem_type,
mount_options=['compress=zstd'] if compression else [], mount_options=['compress=zstd'] if compression else [],
@ -303,14 +310,17 @@ def suggest_single_disk_layout(
# If we don't want to use subvolumes, # If we don't want to use subvolumes,
# But we want to be able to re-use data between re-installs.. # But we want to be able to re-use data between re-installs..
# A second partition for /home would be nice if we have the space for it # A second partition for /home would be nice if we have the space for it
start = root_partition.length home_start = root_partition.length
length = device.device_info.total_size - root_partition.length home_length = device.device_info.total_size - root_partition.length
if using_gpt:
home_length -= align_buffer
home_partition = disk.PartitionModification( home_partition = disk.PartitionModification(
status=disk.ModificationStatus.Create, status=disk.ModificationStatus.Create,
type=disk.PartitionType.Primary, type=disk.PartitionType.Primary,
start=start, start=home_start,
length=length, length=home_length,
mountpoint=Path('/home'), mountpoint=Path('/home'),
fs_type=filesystem_type, fs_type=filesystem_type,
mount_options=['compress=zstd'] if compression else [] mount_options=['compress=zstd'] if compression else []
@ -377,17 +387,21 @@ def suggest_multi_disk_layout(
root_device_sector_size = root_device_modification.device.device_info.sector_size root_device_sector_size = root_device_modification.device.device_info.sector_size
home_device_sector_size = home_device_modification.device.device_info.sector_size home_device_sector_size = home_device_modification.device.device_info.sector_size
root_align_buffer = disk.Size(1, disk.Unit.MiB, root_device_sector_size)
home_align_buffer = disk.Size(1, disk.Unit.MiB, home_device_sector_size)
using_gpt = SysInfo.has_uefi()
# add boot partition to the root device # add boot partition to the root device
boot_partition = _boot_partition(root_device_sector_size) boot_partition = _boot_partition(root_device_sector_size, using_gpt)
root_device_modification.add_partition(boot_partition) root_device_modification.add_partition(boot_partition)
if SysInfo.has_uefi(): root_start = boot_partition.start + boot_partition.length
root_start = disk.Size(513, disk.Unit.MiB, root_device_sector_size)
else:
root_start = disk.Size(206, disk.Unit.MiB, root_device_sector_size)
root_length = root_device.device_info.total_size - root_start root_length = root_device.device_info.total_size - root_start
if using_gpt:
root_length -= root_align_buffer
# add root partition to the root device # add root partition to the root device
root_partition = disk.PartitionModification( root_partition = disk.PartitionModification(
status=disk.ModificationStatus.Create, status=disk.ModificationStatus.Create,
@ -400,15 +414,18 @@ def suggest_multi_disk_layout(
) )
root_device_modification.add_partition(root_partition) root_device_modification.add_partition(root_partition)
start = disk.Size(1, disk.Unit.MiB, home_device_sector_size) home_start = home_align_buffer
length = home_device.device_info.total_size - start home_length = home_device.device_info.total_size - home_start
if using_gpt:
home_length -= home_align_buffer
# add home partition to home device # add home partition to home device
home_partition = disk.PartitionModification( home_partition = disk.PartitionModification(
status=disk.ModificationStatus.Create, status=disk.ModificationStatus.Create,
type=disk.PartitionType.Primary, type=disk.PartitionType.Primary,
start=start, start=home_start,
length=length, length=home_length,
mountpoint=Path('/home'), mountpoint=Path('/home'),
mount_options=['compress=zstd'] if compression else [], mount_options=['compress=zstd'] if compression else [],
fs_type=filesystem_type, fs_type=filesystem_type,