Made it so that the .partitions property of Install() fetches from live data, rather than storing and caching partitions on initation. Since it now supports mounting a partition layout given by external usage.

This commit is contained in:
Anton Hvornum 2021-06-11 17:22:20 +02:00
parent 0a8c061ab4
commit 24476ac1f6
3 changed files with 13 additions and 9 deletions

View File

@ -636,7 +636,7 @@ class Filesystem:
:param string: A raw string passed to /usr/bin/parted -s <string> :param string: A raw string passed to /usr/bin/parted -s <string>
:type string: str :type string: str
""" """
return self.raw_parted(string).exit_code return self.raw_parted(string).exit_code == 0
def use_entire_disk(self, root_filesystem_type='ext4') -> Partition: def use_entire_disk(self, root_filesystem_type='ext4') -> Partition:
# TODO: Implement this with declarative profiles instead. # TODO: Implement this with declarative profiles instead.
@ -652,20 +652,22 @@ class Filesystem:
DiskError("Too many partitions on disk, MBR disks can only have 3 parimary partitions") DiskError("Too many partitions on disk, MBR disks can only have 3 parimary partitions")
if partition_format: if partition_format:
partitioning = self.parted(f'{self.blockdevice.device} mkpart {partition_type} {partition_format} {start} {end}') == 0 parted_string = f'{self.blockdevice.device} mkpart {partition_type} {partition_format} {start} {end}'
else: else:
partitioning = self.parted(f'{self.blockdevice.device} mkpart {partition_type} {start} {end}') == 0 parted_string = f'{self.blockdevice.device} mkpart {partition_type} {start} {end}'
if partitioning: if self.parted(parted_string):
start_wait = time.time() start_wait = time.time()
while previous_partition_uuids == {partition.uuid for partition in self.blockdevice.partitions.values()}: while previous_partition_uuids == {partition.uuid for partition in self.blockdevice.partitions.values()}:
if time.time() - start_wait > 10: if time.time() - start_wait > 10:
raise DiskError(f"New partition never showed up after adding new partition on {self} (timeout 10 seconds).") raise DiskError(f"New partition never showed up after adding new partition on {self} (timeout 10 seconds).")
time.sleep(0.025) time.sleep(0.025)
time.sleep(0.5) # Let the kernel catch up with quick block devices (nvme for instance) time.sleep(0.5) # Let the kernel catch up with quick block devices (nvme for instance)
return self.blockdevice.get_partition(uuid=(previous_partition_uuids ^ {partition.uuid for partition in self.blockdevice.partitions.values()}).pop()) return self.blockdevice.get_partition(uuid=(previous_partition_uuids ^ {partition.uuid for partition in self.blockdevice.partitions.values()}).pop())
def set_name(self, partition: int, name: str): def set_name(self, partition: int, name: str):
return self.parted(f'{self.blockdevice.device} name {partition + 1} "{name}"') == 0 return self.parted(f'{self.blockdevice.device} name {partition + 1} "{name}"') == 0
@ -673,6 +675,7 @@ class Filesystem:
return self.parted(f'{self.blockdevice.device} set {partition + 1} {string}') == 0 return self.parted(f'{self.blockdevice.device} set {partition + 1} {string}') == 0
def parted_mklabel(self, device: str, disk_label: str): def parted_mklabel(self, device: str, disk_label: str):
log(f"Creating a new partition labling on {device}", level=logging.INFO, fg="yellow")
# Try to unmount devices before attempting to run mklabel # Try to unmount devices before attempting to run mklabel
try: try:
SysCommand(f'bash -c "umount {device}?"') SysCommand(f'bash -c "umount {device}?"')

View File

@ -57,7 +57,6 @@ class Installer:
self.post_base_install = [] self.post_base_install = []
storage['session'] = self storage['session'] = self
self.partitions = get_partitions_in_use(self.target)
self.MODULES = [] self.MODULES = []
self.BINARIES = [] self.BINARIES = []
@ -108,6 +107,10 @@ class Installer:
self.sync_log_to_install_medium() self.sync_log_to_install_medium()
return False return False
@property
def partitions(self):
return get_partitions_in_use(self.target)
def sync_log_to_install_medium(self): def sync_log_to_install_medium(self):
# Copy over the install log (if there is one) to the install medium if # Copy over the install log (if there is one) to the install medium if
# at least the base has been strapped in, otherwise we won't have a filesystem/structure to copy to. # at least the base has been strapped in, otherwise we won't have a filesystem/structure to copy to.

View File

@ -224,8 +224,6 @@ def perform_filesystem_operations():
with archinstall.Filesystem(drive, mode) as fs: with archinstall.Filesystem(drive, mode) as fs:
fs.load_layout(archinstall.storage['disk_layouts'][drive]) fs.load_layout(archinstall.storage['disk_layouts'][drive])
perform_installation(archinstall.storage.get('MOUNT_POINT', '/mnt'))
def perform_installation(mountpoint): def perform_installation(mountpoint):
""" """
@ -308,7 +306,7 @@ def perform_installation(mountpoint):
# This step must be after profile installs to allow profiles to install language pre-requisits. # This step must be after profile installs to allow profiles to install language pre-requisits.
# After which, this step will set the language both for console and x11 if x11 was installed for instance. # After which, this step will set the language both for console and x11 if x11 was installed for instance.
installation.set_keyboard_language(archinstall.arguments['keyboard-language']) installation.set_keyboard_language(archinstall.arguments['keyboard-layout'])
if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_post_install(): if archinstall.arguments['profile'] and archinstall.arguments['profile'].has_post_install():
with archinstall.arguments['profile'].load_instructions(namespace=f"{archinstall.arguments['profile'].namespace}.py") as imported: with archinstall.arguments['profile'].load_instructions(namespace=f"{archinstall.arguments['profile'].namespace}.py") as imported:
@ -375,4 +373,4 @@ else:
archinstall.storage['gfx_driver_packages'] = AVAILABLE_GFX_DRIVERS.get(archinstall.arguments.get('gfx_driver', None), None) archinstall.storage['gfx_driver_packages'] = AVAILABLE_GFX_DRIVERS.get(archinstall.arguments.get('gfx_driver', None), None)
perform_filesystem_operations() perform_filesystem_operations()
perform_installation(archinstall.arguments.get('target-mountpoint', None)) perform_installation(archinstall.storage.get('MOUNT_POINT', '/mnt'))