From 850fd2efa812508e2df67aa2b50cff8820389a0d Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 12 Mar 2021 11:30:32 +0530 Subject: Started work on BIOS support --- archinstall/lib/disk.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index c05ba757..16ee72e7 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -5,6 +5,7 @@ from .exceptions import DiskError from .general import * from .output import log, LOG_LEVELS from .storage import storage +from .hardware import hasUEFI ROOT_DIR_PATTERN = re.compile('^.*?/devices') GPT = 0b00000001 @@ -331,9 +332,12 @@ class Filesystem(): # TODO: # When instance of a HDD is selected, check all usages and gracefully unmount them # as well as close any crypto handles. - def __init__(self, blockdevice, mode=GPT): + def __init__(self, blockdevice): self.blockdevice = blockdevice - self.mode = mode + if hasUEFI(): + self.mode = GPT + else: + self.mode = MBR def __enter__(self, *args, **kwargs): if self.blockdevice.keep_partitions is False: @@ -343,6 +347,11 @@ class Filesystem(): return self else: raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt') + elif self.mode == MBR: + if sys_command(f'/usr/bin/parted -s {self.blockdevice.} mklabel msdos').exit_code == 0: + return self + else: + raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel msdos') else: raise DiskError(f'Unknown mode selected to format in: {self.mode}') @@ -405,6 +414,9 @@ class Filesystem(): log(f'Adding partition to {self.blockdevice}', level=LOG_LEVELS.Info) previous_partitions = self.blockdevice.partitions + if self.mode == MBR: + if len(self.blockdevice.partitions())>3: + DiskError("Too many partitions on disk, MBR disks can only have 3 parimary partitions") if format: partitioning = self.parted(f'{self.blockdevice.device} mkpart {type} {format} {start} {end}') == 0 else: -- cgit v1.2.3-70-g09d2 From 563a50dbc0d126c9d2e1038b7e71cf7d30a2fb29 Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 12 Mar 2021 11:59:46 +0530 Subject: fixed mistake in disk.py --- archinstall/lib/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 16ee72e7..cd740571 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -348,7 +348,7 @@ class Filesystem(): else: raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel gpt') elif self.mode == MBR: - if sys_command(f'/usr/bin/parted -s {self.blockdevice.} mklabel msdos').exit_code == 0: + if sys_command(f'/usr/bin/parted -s {self.blockdevice.device} mklabel msdos').exit_code == 0: return self else: raise DiskError(f'Problem setting the partition format to GPT:', f'/usr/bin/parted -s {self.blockdevice.device} mklabel msdos') -- cgit v1.2.3-70-g09d2 From f249476ea7c296459d175262f45c1f8273c6e8ea Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 12 Mar 2021 13:40:54 +0530 Subject: figured out a way to get root device for installing grub --- archinstall/lib/disk.py | 18 ++++++++++-------- archinstall/lib/installer.py | 3 ++- 2 files changed, 12 insertions(+), 9 deletions(-) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index cd740571..d05588a6 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -394,18 +394,20 @@ class Filesystem(): def use_entire_disk(self, root_filesystem_type='ext4', encrypt_root_partition=True): self.add_partition('primary', start='1MiB', end='513MiB', format='vfat') - self.set_name(0, 'EFI') - self.set(0, 'boot on') + #TODO: figure out what do for bios, we don't need a seprate partion for the bootloader + if hasUEFI(): + self.set_name(0, 'EFI') + self.set(0, 'boot on') # TODO: Probably redundant because in GPT mode 'esp on' is an alias for "boot on"? # https://www.gnu.org/software/parted/manual/html_node/set.html - self.set(0, 'esp on') - self.add_partition('primary', start='513MiB', end='100%') + self.set(0, 'esp on') + self.add_partition('primary', start='513MiB', end='100%') - self.blockdevice.partition[0].filesystem = 'vfat' - self.blockdevice.partition[1].filesystem = root_filesystem_type + self.blockdevice.partition[0].filesystem = 'vfat' + self.blockdevice.partition[1].filesystem = root_filesystem_type - self.blockdevice.partition[0].target_mountpoint = '/boot' - self.blockdevice.partition[1].target_mountpoint = '/' + self.blockdevice.partition[0].target_mountpoint = '/boot' + self.blockdevice.partition[1].target_mountpoint = '/' if encrypt_root_partition: self.blockdevice.partition[1].encrypted = True diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index dbcfb973..176b26f4 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -365,7 +365,8 @@ class Installer(): o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB')) sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') else: - o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=--target=i386-pc {self}')) + root_device = subprocess.check_output(f'basename "$(readlink -f "/sys/class/block/{self.partition.path}/..")',shell=True).decode().strip() + o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=--target=i386-pc /dev/{root_device}')) sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') else: raise RequirementError(f"Unknown (or not yet implemented) bootloader added to add_bootloader(): {bootloader}") -- cgit v1.2.3-70-g09d2 From 0637ab6eb0b4be84bb03ffae41113c6a424f71e6 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sun, 28 Mar 2021 23:03:41 +0200 Subject: Adding debug to correct for a potential issue where partitions get marked as encrypted even tho \!disk-password was neven set. --- archinstall/lib/disk.py | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 2eef0e82..c1db3dc9 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -142,7 +142,7 @@ class Partition(): self.target_mountpoint = mountpoint self.filesystem = filesystem self.size = size # TODO: Refresh? - self.encrypted = encrypted + self._encrypted = encrypted self.allow_formatting = False # A fail-safe for unconfigured partitions, such as windows NTFS partitions. if mountpoint: @@ -161,7 +161,7 @@ class Partition(): self.filesystem = fstype if self.filesystem == 'crypto_LUKS': - self.encrypted = True + self._encrypted = True def __lt__(self, left_comparitor): if type(left_comparitor) == Partition: @@ -177,14 +177,23 @@ class Partition(): elif self.target_mountpoint: mount_repr = f", rel_mountpoint={self.target_mountpoint}" - if self.encrypted: + if self._encrypted: return f'Partition(path={self.path}, real_device={self.real_device}, fs={self.filesystem}{mount_repr})' else: return f'Partition(path={self.path}, fs={self.filesystem}{mount_repr})' + @property + def encrypted(self): + return self._encrypted + + @encrypted.setter + def encrypted(self, value :bool): + log(f'Marking {self} as encrypted', level=LOG_LEVELS.Debug) + self._encrypted = value + @property def real_device(self): - if not self.encrypted: + if not self._encrypted: return self.path else: for blockdevice in json.loads(b''.join(sys_command('lsblk -J')).decode('UTF-8'))['blockdevices']: @@ -237,7 +246,7 @@ class Partition(): """ from .luks import luks2 - if not self.encrypted: + if not self._encrypted: raise DiskError(f"Attempting to encrypt a partition that was not marked for encryption: {self}") if not self.safe_to_format(): -- cgit v1.2.3-70-g09d2 From a156f224a87a02d6b0f9a54eef2ce18e418e5187 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 08:56:41 +0200 Subject: Fixing un-encrypted drives matching on block encrypted. --- archinstall/lib/disk.py | 5 +++-- examples/guided.py | 1 + 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index c1db3dc9..85b08bc0 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -142,7 +142,8 @@ class Partition(): self.target_mountpoint = mountpoint self.filesystem = filesystem self.size = size # TODO: Refresh? - self._encrypted = encrypted + self._encrypted = None + self.encrypted = encrypted self.allow_formatting = False # A fail-safe for unconfigured partitions, such as windows NTFS partitions. if mountpoint: @@ -161,7 +162,7 @@ class Partition(): self.filesystem = fstype if self.filesystem == 'crypto_LUKS': - self._encrypted = True + self.encrypted = True def __lt__(self, left_comparitor): if type(left_comparitor) == Partition: diff --git a/examples/guided.py b/examples/guided.py index 4766301e..d9dfe0df 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -292,6 +292,7 @@ def perform_installation(device, boot_partition, language, mirrors): Only requirement is that the block devices are formatted and setup prior to entering this function. """ + print('Installing on:', device) with archinstall.Installer(device, boot_partition=boot_partition, hostname=archinstall.arguments.get('hostname', 'Archinstall')) as installation: ## if len(mirrors): # Certain services might be running that affects the system during installation. -- cgit v1.2.3-70-g09d2 From 3161cd8afff2def3d4d3057cb028c666c4db55a3 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Mon, 29 Mar 2021 09:09:25 +0200 Subject: Fixing rare occation where partitions dissapear just before .format(). --- archinstall/lib/disk.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 85b08bc0..9afece2e 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -270,6 +270,11 @@ class Partition(): if allow_formatting is None: allow_formatting = self.allow_formatting + # To avoid "unable to open /dev/x: No such file or directory" + start_wait = time.time() + while pathlib.Path(path).exists() is False and time.time() - start_wait < 10: + time.sleep(0.025) + if not allow_formatting: raise PermissionError(f"{self} is not formatable either because instance is locked ({self.allow_formatting}) or a blocking flag was given ({allow_formatting})") -- cgit v1.2.3-70-g09d2 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(+) (limited to 'archinstall/lib/disk.py') 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(-) (limited to 'archinstall/lib/disk.py') 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(-) (limited to 'archinstall/lib/disk.py') 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(-) (limited to 'archinstall/lib/disk.py') 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(-) (limited to 'archinstall/lib/disk.py') 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(+) (limited to 'archinstall/lib/disk.py') 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(-) (limited to 'archinstall/lib/disk.py') 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(-) (limited to 'archinstall/lib/disk.py') 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(-) (limited to 'archinstall/lib/disk.py') 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(-) (limited to 'archinstall/lib/disk.py') 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(-) (limited to 'archinstall/lib/disk.py') 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(-) (limited to 'archinstall/lib/disk.py') 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(-) (limited to 'archinstall/lib/disk.py') 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(+) (limited to 'archinstall/lib/disk.py') 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(-) (limited to 'archinstall/lib/disk.py') 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 From b974b93004efa9912e404f5d3fca7c44a58dc0e3 Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 2 Apr 2021 10:08:16 +0530 Subject: fixed some issues with the changes --- archinstall/lib/disk.py | 7 ++----- archinstall/lib/installer.py | 12 +++++++++++- examples/guided.py | 8 +++++++- 3 files changed, 20 insertions(+), 7 deletions(-) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index fbc11ca3..8e9e0234 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -390,12 +390,9 @@ class Filesystem(): # TODO: # When instance of a HDD is selected, check all usages and gracefully unmount them # as well as close any crypto handles. - def __init__(self, blockdevice): + def __init__(self, blockdevice,mode): self.blockdevice = blockdevice - if hasUEFI(): - self.mode = GPT - else: - self.mode = MBR + self.mode = mode def __enter__(self, *args, **kwargs): if self.blockdevice.keep_partitions is False: diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index d161c3b7..492d7715 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -1,4 +1,4 @@ -import os, stat, time, shutil, pathlib +import os, stat, time, shutil, pathlib, subprocess from .exceptions import * from .disk import * @@ -398,6 +398,16 @@ class Installer(): break raise RequirementError(f"Could not identify the UUID of {self.partition}, there for {self.mountpoint}/boot/loader/entries/arch.conf will be broken until fixed.") + elif bootloader == "grub-install": + if hasUEFI(): + o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=GRUB')) + sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') + else: + root_device = subprocess.check_output(f'basename "$(readlink -f "/sys/class/block/{self.partition.path.strip("/dev/")}/..")',shell=True).decode().strip() + if root_device == "block": + root_device = f"{self.partition.path}" + o = b''.join(sys_command(f'/usr/bin/arch-chroot {self.mountpoint} grub-install --target=--target=i386-pc /dev/{root_device}')) + sys_command('/usr/bin/arch-chroot grub-mkconfig -o /boot/grub/grub.cfg') else: raise RequirementError(f"Unknown (or not yet implemented) bootloader added to add_bootloader(): {bootloader}") diff --git a/examples/guided.py b/examples/guided.py index 71e1e01d..f374a41c 100644 --- a/examples/guided.py +++ b/examples/guided.py @@ -1,5 +1,6 @@ import getpass, time, json, sys, signal, os import archinstall +from archinstall.lib.hardware import hasUEFI """ This signal-handler chain (and global variable) @@ -244,7 +245,12 @@ def perform_installation_steps(): Setup the blockdevice, filesystem (and optionally encryption). Once that's done, we'll hand over to perform_installation() """ - with archinstall.Filesystem(archinstall.arguments['harddrive'], archinstall.GPT) as fs: + # maybe we can ask the user what they would prefer on uefi systems? + if hasUEFI(): + mode = archinstall.GPT + else: + mode = archinstall.MBR + with archinstall.Filesystem(archinstall.arguments['harddrive'],mode) 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')) -- cgit v1.2.3-70-g09d2 From 655ec06119ee67cbf58733f2f1902c606006bef9 Mon Sep 17 00:00:00 2001 From: advaithm Date: Fri, 2 Apr 2021 10:12:45 +0530 Subject: accidentlly called dict as function --- archinstall/lib/disk.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 8e9e0234..fdc2fbc5 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -481,7 +481,7 @@ class Filesystem(): previous_partitions = self.blockdevice.partitions if self.mode == MBR: - if len(self.blockdevice.partitions())>3: + if len(self.blockdevice.partitions)>3: DiskError("Too many partitions on disk, MBR disks can only have 3 parimary partitions") if format: partitioning = self.parted(f'{self.blockdevice.device} mkpart {type} {format} {start} {end}') == 0 -- cgit v1.2.3-70-g09d2