From 68c2988358426e8d0074479cef539ddadc2a31e6 Mon Sep 17 00:00:00 2001 From: Victor Gavro Date: Sat, 5 Feb 2022 00:58:44 +0200 Subject: disk layout: allow to omit partition "start" option to start from previous partition end (#895) * disk layout: allow to omit partition "start" option to start from previous partition end * mixed tabs/spaces fixes * Update filesystem.py Co-authored-by: Anton Hvornum --- archinstall/lib/disk/filesystem.py | 12 +++++++++++- archinstall/lib/disk/partition.py | 9 +++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) (limited to 'archinstall/lib') diff --git a/archinstall/lib/disk/filesystem.py b/archinstall/lib/disk/filesystem.py index 64b8008c..c8a74e3f 100644 --- a/archinstall/lib/disk/filesystem.py +++ b/archinstall/lib/disk/filesystem.py @@ -18,6 +18,11 @@ from ..storage import storage GPT = 0b00000001 MBR = 0b00000010 +# A sane default is 5MiB, that allows for plenty of buffer for GRUB on MBR +# but also 4MiB for memory cards for instance. And another 1MiB to avoid issues. +# (we've been pestered by disk issues since the start, so please let this be here for a few versions) +DEFAULT_PARTITION_START = '5MiB' + class Filesystem: # TODO: # When instance of a HDD is selected, check all usages and gracefully unmount them @@ -73,13 +78,16 @@ class Filesystem: self.blockdevice.flush_cache() + prev_partition = None # We then iterate the partitions in order for partition in layout.get('partitions', []): # We don't want to re-add an existing partition (those containing a UUID already) if partition.get('wipe', False) and not partition.get('PARTUUID', None): print("Adding partition....") + start = partition.get('start') or ( + prev_partition and f'{prev_partition["device_instance"].end_sectors}s' or DEFAULT_PARTITION_START) partition['device_instance'] = self.add_partition(partition.get('type', 'primary'), - start=partition.get('start', '1MiB'), # TODO: Revisit sane block starts (4MB for memorycards for instance) + start=start, end=partition.get('size', '100%'), partition_format=partition.get('filesystem', {}).get('format', 'btrfs')) # TODO: device_instance some times become None @@ -143,6 +151,8 @@ class Filesystem: log(f"Marking partition {partition['device_instance']} as bootable.") self.set(self.partuuid_to_index(partition['device_instance'].uuid), 'boot on') + prev_partition = partition + def find_partition(self, mountpoint :str) -> Partition: for partition in self.blockdevice: if partition.target_mountpoint == mountpoint or partition.mountpoint == mountpoint: diff --git a/archinstall/lib/disk/partition.py b/archinstall/lib/disk/partition.py index afd34f20..7bfde64c 100644 --- a/archinstall/lib/disk/partition.py +++ b/archinstall/lib/disk/partition.py @@ -114,6 +114,7 @@ class Partition: @property def end(self) -> Optional[str]: + # TODO: actually this is size in sectors unit # TODO: Verify that the logic holds up, that 'size' is the size without 'start' added to it. output = json.loads(SysCommand(f"sfdisk --json {self.block_device.path}").decode('UTF-8')) @@ -121,6 +122,14 @@ class Partition: if partition['node'] == self.path: return partition['size'] # * self.sector_size + @property + def end_sectors(self) -> Optional[str]: + output = json.loads(SysCommand(f"sfdisk --json {self.block_device.path}").decode('UTF-8')) + + for partition in output.get('partitiontable', {}).get('partitions', []): + if partition['node'] == self.path: + return partition['start'] + partition['size'] + @property def size(self) -> Optional[float]: for i in range(storage['DISK_RETRY_ATTEMPTS']): -- cgit v1.2.3-54-g00ecf