Add linux-home partition flag (#2898)

This commit is contained in:
codefiles 2024-11-20 09:32:29 -05:00 committed by GitHub
parent 611af783aa
commit 0eac05cecc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 3 deletions

View File

@ -28,6 +28,7 @@ from .device_model import (
LvmVolumeGroup, LvmVolumeGroup,
LvmVolumeInfo, LvmVolumeInfo,
ModificationStatus, ModificationStatus,
PartitionFlag,
PartitionGUID, PartitionGUID,
PartitionModification, PartitionModification,
PartitionTable, PartitionTable,
@ -543,8 +544,11 @@ class DeviceHandler:
except PartitionException as ex: except PartitionException as ex:
raise DiskError(f'Unable to add partition, most likely due to overlapping sectors: {ex}') from ex raise DiskError(f'Unable to add partition, most likely due to overlapping sectors: {ex}') from ex
if disk.type == PartitionTable.GPT.value and part_mod.is_root(): if disk.type == PartitionTable.GPT.value:
partition.type_uuid = PartitionGUID.LINUX_ROOT_X86_64.bytes if part_mod.is_root():
partition.type_uuid = PartitionGUID.LINUX_ROOT_X86_64.bytes
elif PartitionFlag.LINUX_HOME not in part_mod.flags and part_mod.is_home():
partition.setFlag(PartitionFlag.LINUX_HOME.flag_id)
# the partition has a path now that it has been added # the partition has a path now that it has been added
part_mod.dev_path = Path(partition.path) part_mod.dev_path = Path(partition.path)

View File

@ -594,6 +594,7 @@ class PartitionFlag(PartitionFlagDataMixin, Enum):
Boot = parted.PARTITION_BOOT Boot = parted.PARTITION_BOOT
XBOOTLDR = parted.PARTITION_BLS_BOOT, "bls_boot" XBOOTLDR = parted.PARTITION_BLS_BOOT, "bls_boot"
ESP = parted.PARTITION_ESP ESP = parted.PARTITION_ESP
LINUX_HOME = parted.PARTITION_LINUX_HOME, "linux-home"
@property @property
def description(self) -> str: def description(self) -> str:
@ -814,6 +815,12 @@ class PartitionModification:
return False return False
def is_home(self) -> bool:
return (
self.mountpoint == Path('/home')
or PartitionFlag.LINUX_HOME in self.flags
)
def is_modify(self) -> bool: def is_modify(self) -> bool:
return self.status == ModificationStatus.Modify return self.status == ModificationStatus.Modify

View File

@ -411,6 +411,10 @@ def suggest_single_disk_layout(
home_start = root_partition.start + root_partition.length home_start = root_partition.start + root_partition.length
home_length = available_space - home_start home_length = available_space - home_start
flags = []
if using_gpt:
flags.append(disk.PartitionFlag.LINUX_HOME)
home_partition = disk.PartitionModification( home_partition = disk.PartitionModification(
status=disk.ModificationStatus.Create, status=disk.ModificationStatus.Create,
type=disk.PartitionType.Primary, type=disk.PartitionType.Primary,
@ -418,7 +422,8 @@ def suggest_single_disk_layout(
length=home_length, length=home_length,
mountpoint=Path('/home'), mountpoint=Path('/home'),
fs_type=filesystem_type, fs_type=filesystem_type,
mount_options=mount_options mount_options=mount_options,
flags=flags
) )
device_modification.add_partition(home_partition) device_modification.add_partition(home_partition)
@ -514,8 +519,10 @@ def suggest_multi_disk_layout(
home_start = home_align_buffer home_start = home_align_buffer
home_length = home_device.device_info.total_size - home_start home_length = home_device.device_info.total_size - home_start
flags = []
if using_gpt: if using_gpt:
home_length -= home_align_buffer home_length -= home_align_buffer
flags.append(disk.PartitionFlag.LINUX_HOME)
# add home partition to home device # add home partition to home device
home_partition = disk.PartitionModification( home_partition = disk.PartitionModification(
@ -526,6 +533,7 @@ def suggest_multi_disk_layout(
mountpoint=Path('/home'), mountpoint=Path('/home'),
mount_options=mount_options, mount_options=mount_options,
fs_type=filesystem_type, fs_type=filesystem_type,
flags=flags
) )
home_device_modification.add_partition(home_partition) home_device_modification.add_partition(home_partition)