From e94a8d8b25060e0ab2a47215d773825e649a43aa Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 13:16:42 +0200 Subject: Debugging --- archinstall/lib/disk.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 9afece2e..5e16558e 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -452,6 +452,8 @@ class Filesystem(): self.blockdevice.partition[1].allow_formatting = True if encrypt_root_partition: + raise ValueError("moo") + exit(1) log(f"Marking partition {self.blockdevice.partition[1]} as encrypted.", level=LOG_LEVELS.Debug) self.blockdevice.partition[1].encrypted = True -- cgit v1.2.3-70-g09d2 From 0e269752479ff68fba73d4c04ea0f28718f945cd Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 15:55:36 +0200 Subject: Adding callstack to debug output for easier debugging. Removed hardcoded debug crash --- archinstall/lib/disk.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 5e16558e..3efee8b4 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -1,5 +1,5 @@ import glob, re, os, json, time, hashlib -import pathlib +import pathlib, traceback from collections import OrderedDict from .exceptions import DiskError from .general import * @@ -452,9 +452,9 @@ class Filesystem(): self.blockdevice.partition[1].allow_formatting = True if encrypt_root_partition: - raise ValueError("moo") - exit(1) log(f"Marking partition {self.blockdevice.partition[1]} as encrypted.", level=LOG_LEVELS.Debug) + log(f"Callstrack when marking the partition: {''.join(traceback.format_stack())}", level=LOG_LEVELS.Debug) + self.blockdevice.partition[1].encrypted = True def add_partition(self, type, start, end, format=None): -- cgit v1.2.3-70-g09d2 From 39cb0b94d94c3f4fa0dec4002e8d9221fb28c753 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 15:57:31 +0200 Subject: Moved some debugging to catch more variable settings. --- archinstall/lib/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 3efee8b4..7bc09a0b 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -190,6 +190,7 @@ class Partition(): @encrypted.setter def encrypted(self, value :bool): log(f'Marking {self} as encrypted', level=LOG_LEVELS.Debug) + log(f"Callstrack when marking the partition: {''.join(traceback.format_stack())}", level=LOG_LEVELS.Debug) self._encrypted = value @property @@ -453,7 +454,6 @@ class Filesystem(): if encrypt_root_partition: log(f"Marking partition {self.blockdevice.partition[1]} as encrypted.", level=LOG_LEVELS.Debug) - log(f"Callstrack when marking the partition: {''.join(traceback.format_stack())}", level=LOG_LEVELS.Debug) self.blockdevice.partition[1].encrypted = True -- cgit v1.2.3-70-g09d2 From d26c1f820ddef17bfd9d1a536fbc8a068e815ff6 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 16:11:30 +0200 Subject: Toned down the debugging a bit. --- archinstall/lib/disk.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 7bc09a0b..0e42feca 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -189,8 +189,9 @@ class Partition(): @encrypted.setter def encrypted(self, value :bool): - log(f'Marking {self} as encrypted', level=LOG_LEVELS.Debug) - log(f"Callstrack when marking the partition: {''.join(traceback.format_stack())}", level=LOG_LEVELS.Debug) + if value: + log(f'Marking {self} as encrypted: {value}', level=LOG_LEVELS.Debug) + log(f"Callstrack when marking the partition: {''.join(traceback.format_stack())}", level=LOG_LEVELS.Debug) self._encrypted = value @property -- cgit v1.2.3-70-g09d2 From 5e9c973d42125bb809443670c1e30439e4b11b17 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 16:51:30 +0200 Subject: Added support for flushing a BlockDevice() cache after a partition has been formatted. This is to avoid internal confusion of which partitions are encrypted or not when going from Encrypted -> Un-encrypted setups. --- archinstall/lib/disk.py | 11 +++++++++-- archinstall/lib/luks.py | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 0e42feca..518c1503 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -107,7 +107,7 @@ class BlockDevice(): if part_id not in self.part_cache: ## TODO: Force over-write even if in cache? if part_id not in self.part_cache or self.part_cache[part_id].size != part['size']: - self.part_cache[part_id] = Partition(root_path + part_id, part_id=part_id, size=part['size']) + self.part_cache[part_id] = Partition(root_path + part_id, self, part_id=part_id, size=part['size']) return {k: self.part_cache[k] for k in sorted(self.part_cache)} @@ -133,9 +133,11 @@ class BlockDevice(): self.part_cache = OrderedDict() class Partition(): - def __init__(self, path, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True): + def __init__(self, path :str, block_device :BlockDevice, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True): if not part_id: part_id = os.path.basename(path) + + self.block_device = block_device self.path = path self.part_id = part_id self.mountpoint = mountpoint @@ -192,6 +194,7 @@ class Partition(): if value: log(f'Marking {self} as encrypted: {value}', level=LOG_LEVELS.Debug) log(f"Callstrack when marking the partition: {''.join(traceback.format_stack())}", level=LOG_LEVELS.Debug) + self._encrypted = value @property @@ -318,6 +321,10 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") + + if self.block_device: + self.block_device.flush_cache() + return True def find_parent_of(self, data, name, parent=None): diff --git a/archinstall/lib/luks.py b/archinstall/lib/luks.py index 30c38ec8..19c21795 100644 --- a/archinstall/lib/luks.py +++ b/archinstall/lib/luks.py @@ -113,7 +113,7 @@ class luks2(): sys_command(f'/usr/bin/cryptsetup open {partition.path} {mountpoint} --key-file {os.path.abspath(key_file)} --type luks2') if os.path.islink(f'/dev/mapper/{mountpoint}'): self.mapdev = f'/dev/mapper/{mountpoint}' - unlocked_partition = Partition(self.mapdev, encrypted=True, filesystem=get_filesystem_type(self.mapdev), autodetect_filesystem=False) + unlocked_partition = Partition(self.mapdev, None, encrypted=True, filesystem=get_filesystem_type(self.mapdev), autodetect_filesystem=False) unlocked_partition.allow_formatting = self.partition.allow_formatting return unlocked_partition -- cgit v1.2.3-70-g09d2 From f3907310e3fbbc07ad31f3558279cd73ba774472 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 16:59:09 +0200 Subject: Allowing individual partitions safety checks to rely on the parent blockdevice keep_partitions status. --- archinstall/lib/disk.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 518c1503..d6d28935 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -237,6 +237,9 @@ class Partition(): return True if files > 0 else False def safe_to_format(self): + if self.block_device and self.block_device.keep_partitions is True: + return True + if self.allow_formatting is False: log(f"Partition {self} is not marked for formatting.", level=LOG_LEVELS.Debug) return False -- cgit v1.2.3-70-g09d2 From a0980afff1d2458d348e144cb0d8351f862564c1 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 17:32:48 +0200 Subject: Experimenting with carrying over flags across cache flush. This to solve issues when flush is cleared and target mountpoints gets lost, making it impossible to do .find_mountpoint('/') later on for instance. --- archinstall/lib/disk.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index d6d28935..84a4ff37 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -130,7 +130,20 @@ class BlockDevice(): return False def flush_cache(self): + old_partitions = {**self.partitions} + self.part_cache = OrderedDict() + # Trigger a refresh of the cache + if len(self.partitions): + pass + + # Carry over any flags from the previous partitions + for partition in old_partitions: + if partition in self.part_cache: + if self.part_cache[partition].size == old_partitions[partition].size and \ + self.part_cache[partition].filesystem == old_partitions[partition].filesystem: + print('Carrying over', self.part_cache[partition].target_mountpoint) + self.part_cache[partition].target_mountpoint = old_partitions[partition].target_mountpoint class Partition(): def __init__(self, path :str, block_device :BlockDevice, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True): @@ -237,7 +250,9 @@ class Partition(): return True if files > 0 else False def safe_to_format(self): - if self.block_device and self.block_device.keep_partitions is True: + if self.block_device and self.block_device.keep_partitions is False: + # If we don't intend to keep any partitions on the parent block device + # We're good to format. return True if self.allow_formatting is False: @@ -325,6 +340,7 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") + # self.encrypted = False if self.filesystem != 'crypto_LUKS' else True if self.block_device: self.block_device.flush_cache() -- cgit v1.2.3-70-g09d2 From 512f0327f0d5eb9e507050ff9a4325e9728df705 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 17:34:13 +0200 Subject: Experimenting with cache, carrying over .allow_formatting --- archinstall/lib/disk.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 84a4ff37..3e512034 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -142,8 +142,9 @@ class BlockDevice(): if partition in self.part_cache: if self.part_cache[partition].size == old_partitions[partition].size and \ self.part_cache[partition].filesystem == old_partitions[partition].filesystem: - print('Carrying over', self.part_cache[partition].target_mountpoint) + print('Carrying over', self.part_cache[partition].target_mountpoint, self.part_cache[partition].allow_formatting) self.part_cache[partition].target_mountpoint = old_partitions[partition].target_mountpoint + self.part_cache[partition].allow_formatting = old_partitions[partition].allow_formatting class Partition(): def __init__(self, path :str, block_device :BlockDevice, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True): -- cgit v1.2.3-70-g09d2 From a29bd759548c02c609aa43d9536475b1259a70f9 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 17:46:07 +0200 Subject: Removing a flush of the cache that was excessive. --- archinstall/lib/disk.py | 25 ++----------------------- examples/guided.py | 8 ++++---- 2 files changed, 6 insertions(+), 27 deletions(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 3e512034..4e70a4a5 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -130,21 +130,7 @@ class BlockDevice(): return False def flush_cache(self): - old_partitions = {**self.partitions} - self.part_cache = OrderedDict() - # Trigger a refresh of the cache - if len(self.partitions): - pass - - # Carry over any flags from the previous partitions - for partition in old_partitions: - if partition in self.part_cache: - if self.part_cache[partition].size == old_partitions[partition].size and \ - self.part_cache[partition].filesystem == old_partitions[partition].filesystem: - print('Carrying over', self.part_cache[partition].target_mountpoint, self.part_cache[partition].allow_formatting) - self.part_cache[partition].target_mountpoint = old_partitions[partition].target_mountpoint - self.part_cache[partition].allow_formatting = old_partitions[partition].allow_formatting class Partition(): def __init__(self, path :str, block_device :BlockDevice, part_id=None, size=-1, filesystem=None, mountpoint=None, encrypted=False, autodetect_filesystem=True): @@ -341,9 +327,7 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") - # self.encrypted = False if self.filesystem != 'crypto_LUKS' else True - if self.block_device: - self.block_device.flush_cache() + self.encrypted = False if self.filesystem != 'crypto_LUKS' else True return True @@ -460,7 +444,7 @@ class Filesystem(): """ return self.raw_parted(string).exit_code - def use_entire_disk(self, root_filesystem_type='ext4', encrypt_root_partition=True): + def use_entire_disk(self, root_filesystem_type='ext4'): log(f"Using and formatting the entire {self.blockdevice}.", level=LOG_LEVELS.Debug) self.add_partition('primary', start='1MiB', end='513MiB', format='fat32') self.set_name(0, 'EFI') @@ -480,11 +464,6 @@ class Filesystem(): self.blockdevice.partition[0].allow_formatting = True self.blockdevice.partition[1].allow_formatting = True - if encrypt_root_partition: - log(f"Marking partition {self.blockdevice.partition[1]} as encrypted.", level=LOG_LEVELS.Debug) - - self.blockdevice.partition[1].encrypted = True - def add_partition(self, type, start, end, format=None): log(f'Adding partition to {self.blockdevice}', level=LOG_LEVELS.Info) diff --git a/examples/guided.py b/examples/guided.py index 92331450..71e1e01d 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -247,10 +247,10 @@ def perform_installation_steps(): with archinstall.Filesystem(archinstall.arguments['harddrive'], archinstall.GPT) as fs: # Wipe the entire drive if the disk flag `keep_partitions`is False. if archinstall.arguments['harddrive'].keep_partitions is False: - fs.use_entire_disk(root_filesystem_type=archinstall.arguments.get('filesystem', 'btrfs'), - encrypt_root_partition=archinstall.arguments.get('!encryption-password', False)) - # Otherwise, check if encryption is desired and mark the root partition as encrypted. - elif archinstall.arguments.get('!encryption-password', None): + fs.use_entire_disk(root_filesystem_type=archinstall.arguments.get('filesystem', 'btrfs')) + + # Check if encryption is desired and mark the root partition as encrypted. + if archinstall.arguments.get('!encryption-password', None): root_partition = fs.find_partition('/') root_partition.encrypted = True -- cgit v1.2.3-70-g09d2 From 0c86440e2e63c5e66e64679e79ff675b9cc3f1dd Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 17:47:34 +0200 Subject: Rolling back change to check parent blockdevice for safe formatting, it would wipe the boot partition if the boot partition for multiple drives was shared on the specific drive. --- archinstall/lib/disk.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 4e70a4a5..f0651685 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -237,11 +237,6 @@ class Partition(): return True if files > 0 else False def safe_to_format(self): - if self.block_device and self.block_device.keep_partitions is False: - # If we don't intend to keep any partitions on the parent block device - # We're good to format. - return True - if self.allow_formatting is False: log(f"Partition {self} is not marked for formatting.", level=LOG_LEVELS.Debug) return False -- cgit v1.2.3-70-g09d2 From 1b903550b588d1ade90eae034b757e2950398550 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 17:53:30 +0200 Subject: Reworking cache logic to not loose .encrypted flag on partitions after flushing cache. --- archinstall/lib/disk.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index f0651685..18006311 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -322,7 +322,8 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") - self.encrypted = False if self.filesystem != 'crypto_LUKS' else True + if get_filesystem_type(path) == 'crypto_LUKS': + self.encrypted = True return True -- cgit v1.2.3-70-g09d2 From 8c8a441c2627a180671eb7fcd95b3a0f8d0a102e Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 18:10:02 +0200 Subject: Added some debugging. --- archinstall/lib/disk.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 18006311..23fbf621 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -322,7 +322,9 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") - if get_filesystem_type(path) == 'crypto_LUKS': + print('Checking if encrypted:', path) + print('Also checking:', self.real_device) + if get_filesystem_type(path) == 'crypto_LUKS' or get_filesystem_type(self.real_device) == 'crypto_LUKS': self.encrypted = True return True -- cgit v1.2.3-70-g09d2 From a50aa59060591a121a7b58e58487b6a2840825f3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 18:11:46 +0200 Subject: Adding .encrypted logic after .format calls to correctly identify partitions as encrypted/not-encrypted. This after a .flush_cache has been called. --- archinstall/lib/disk.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 23fbf621..9ad49ac2 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -322,10 +322,10 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") - print('Checking if encrypted:', path) - print('Also checking:', self.real_device) if get_filesystem_type(path) == 'crypto_LUKS' or get_filesystem_type(self.real_device) == 'crypto_LUKS': self.encrypted = True + else: + self.encrypted = False return True -- cgit v1.2.3-70-g09d2 From 151c90a56d2dbf4daa7edb5545d25e2484df08f7 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 18:12:05 +0200 Subject: Added some debugging. --- archinstall/lib/disk.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 9ad49ac2..0425321d 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -322,6 +322,8 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") + print('Checking if encrypted:', path) + print('Also checking:', self.real_device) if get_filesystem_type(path) == 'crypto_LUKS' or get_filesystem_type(self.real_device) == 'crypto_LUKS': self.encrypted = True else: -- cgit v1.2.3-70-g09d2 From b03de49f0f6d29ec8cb7588c2216eb70d523e74d Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 18:17:09 +0200 Subject: Removed debugging and finalized fix. --- archinstall/lib/disk.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 0425321d..9ad49ac2 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -322,8 +322,6 @@ class Partition(): else: raise UnknownFilesystemFormat(f"Fileformat '{filesystem}' is not yet implemented.") - print('Checking if encrypted:', path) - print('Also checking:', self.real_device) if get_filesystem_type(path) == 'crypto_LUKS' or get_filesystem_type(self.real_device) == 'crypto_LUKS': self.encrypted = True else: -- cgit v1.2.3-70-g09d2