From 1aa738691e261b3dfaf5195ec7636617a283d47a Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Tue, 25 Jan 2022 16:09:34 +0100 Subject: Fixing the 'device_instance' being None in some partition places (#902) * Added a new return value from add_partition. Also added an exception to make sure `add_partition` can't continue silently * Added a log of debugging to add_partition * Removed a blank line (flake8) * Misconfigured variable * Added some more debugging information to partprobe * FIX: disk layout: partprobe should be called and checked only for target device (#896) * disk layout: partprobe should be called and checked only for target device * disk layout: partprobe: removed unnecessary bash subprocess * Properly defined BlockDevice() on Partition() creation. Also made sure mount-checks got some rrro handling and non-block devices should no longer attempt to return a size Co-authored-by: Anton Hvornum Co-authored-by: Victor Gavro --- archinstall/lib/disk/helpers.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'archinstall/lib/disk/helpers.py') diff --git a/archinstall/lib/disk/helpers.py b/archinstall/lib/disk/helpers.py index e9f6bc10..26f701d2 100644 --- a/archinstall/lib/disk/helpers.py +++ b/archinstall/lib/disk/helpers.py @@ -190,10 +190,26 @@ def get_partitions_in_use(mountpoint :str) -> List[Partition]: output = json.loads(output) for target in output.get('filesystems', []): - mounts.append(Partition(target['source'], None, filesystem=target.get('fstype', None), mountpoint=target['target'])) + # We need to create a BlockDevice() instead of 'None' here when creaiting Partition() + # Otherwise subsequent calls to .size etc will fail due to BlockDevice being None. + + # So first, we create the partition without a BlockDevice and carefully only use it to get .real_device + # Note: doing print(partition) here will break because the above mentioned issue. + partition = Partition(target['source'], None, filesystem=target.get('fstype', None), mountpoint=target['target']) + partition = Partition(target['source'], partition.real_device, filesystem=target.get('fstype', None), mountpoint=target['target']) + + # Once we have the real device (for instance /dev/nvme0n1p5) we can find the parent block device using + # (lsblk pkname lists both the partition and blockdevice, BD being the last entry) + result = SysCommand(f'lsblk -no pkname {partition.real_device}').decode().rstrip('\r\n').split('\r\n')[-1] + block_device = BlockDevice(f"/dev/{result}") + + # Once we figured the block device out, we can properly create the partition object + partition = Partition(target['source'], block_device, filesystem=target.get('fstype', None), mountpoint=target['target']) + + mounts.append(partition) for child in target.get('children', []): - mounts.append(Partition(child['source'], None, filesystem=child.get('fstype', None), mountpoint=child['target'])) + mounts.append(Partition(child['source'], block_device, filesystem=child.get('fstype', None), mountpoint=child['target'])) return mounts -- cgit v1.2.3-54-g00ecf