From 05e848ce626c768bc6bfbcdbfa65083abb035b87 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 9 Apr 2021 11:45:06 +0200 Subject: Made sure the mount target path exists before mounting. --- archinstall/lib/disk.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index dbb69662..7e02c539 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -366,14 +366,16 @@ class Partition(): if not fs: if not self.filesystem: raise DiskError(f'Need to format (or define) the filesystem on {self} before mounting.') fs = self.filesystem - ## libc has some issues with loop devices, defaulting back to sys calls - # ret = libc.mount(self.path.encode(), target.encode(), fs.encode(), 0, options.encode()) - # if ret < 0: - # errno = ctypes.get_errno() - # raise OSError(errno, f"Error mounting {self.path} ({fs}) on {target} with options '{options}': {os.strerror(errno)}") - if sys_command(f'/usr/bin/mount {self.path} {target}').exit_code == 0: - self.mountpoint = target - return True + + pathlib.Path(self.path).mkdir(parents=True, exist_ok=True) + + try: + sys_command(f'/usr/bin/mount {self.path} {target}') + except SysCallError as err: + raise err + + self.mountpoint = target + return True def unmount(self): try: -- cgit v1.2.3-54-g00ecf From 1395f0888c52f01a231aec6c437d570895a03210 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 9 Apr 2021 11:45:45 +0200 Subject: Wrong variable. --- 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 7e02c539..f0fe7181 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -367,7 +367,7 @@ class Partition(): if not self.filesystem: raise DiskError(f'Need to format (or define) the filesystem on {self} before mounting.') fs = self.filesystem - pathlib.Path(self.path).mkdir(parents=True, exist_ok=True) + pathlib.Path(target).mkdir(parents=True, exist_ok=True) try: sys_command(f'/usr/bin/mount {self.path} {target}') -- cgit v1.2.3-54-g00ecf From eb0ae8b1c35e421f88b7eabcc445d1069969ba76 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 9 Apr 2021 11:53:54 +0200 Subject: Added disk helper function get_partitions_in_use(). Which returns which partions are being used at a given mount location, including children. --- archinstall/lib/disk.py | 18 ++++++++++++++++++ archinstall/lib/installer.py | 1 + 2 files changed, 19 insertions(+) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index f0fe7181..af40e36f 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -574,6 +574,24 @@ def get_mount_info(path): return output['filesystems'][0] +def get_partitions_in_use(mountpoint): + try: + output = b''.join(sys_command(f'/usr/bin/findmnt --json -R {path}')) + except SysCallError: + return {} + + mounts = [] + + output = output.decode('UTF-8') + output = json.loads(output) + for target in output.get('filesystems', []): + mounts.append(Partition(target['source'], filesystem=target.get('fstype', None), mountpoint=target['target'])) + + for child in target.get('children', []): + mounts.append(Partition(child['source'], filesystem=child.get('fstype', None), mountpoint=child['target'])) + + return mounts + def get_filesystem_type(path): try: handle = sys_command(f"blkid -o value -s TYPE {path}") diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 11f75f99..d17ee77c 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -49,6 +49,7 @@ class Installer(): storage['session'] = self self.partitions = get_partitions_in_use(self.target) + print(self.partitions) def log(self, *args, level=LOG_LEVELS.Debug, **kwargs): """ -- cgit v1.2.3-54-g00ecf From eb7ed1126bcfece5ec2fba40b24227e02082bea0 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 9 Apr 2021 11:54:48 +0200 Subject: Wrong variable name --- 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 af40e36f..f8bdc040 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -576,7 +576,7 @@ def get_mount_info(path): def get_partitions_in_use(mountpoint): try: - output = b''.join(sys_command(f'/usr/bin/findmnt --json -R {path}')) + output = b''.join(sys_command(f'/usr/bin/findmnt --json -R {mountpoint}')) except SysCallError: return {} -- cgit v1.2.3-54-g00ecf From db7b3c8cca10068f3c2186b3c1d6eb316741f3a0 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 9 Apr 2021 11:56:35 +0200 Subject: Attempting default value None for block device to partition. --- 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 f8bdc040..f6dc16eb 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -585,10 +585,10 @@ def get_partitions_in_use(mountpoint): output = output.decode('UTF-8') output = json.loads(output) for target in output.get('filesystems', []): - mounts.append(Partition(target['source'], filesystem=target.get('fstype', None), mountpoint=target['target'])) + mounts.append(Partition(target['source'], None, filesystem=target.get('fstype', None), mountpoint=target['target'])) for child in target.get('children', []): - mounts.append(Partition(child['source'], filesystem=child.get('fstype', None), mountpoint=child['target'])) + mounts.append(Partition(child['source'], None, filesystem=child.get('fstype', None), mountpoint=child['target'])) return mounts -- cgit v1.2.3-54-g00ecf From 5099376dcdf59cbfcd146f3c2fa92872b2b1920c Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 9 Apr 2021 21:50:53 +0200 Subject: Attempting to fix auto-detection of encrypted drives. So that #124 can perform reverse detection on partitions and detect encryption. --- archinstall/lib/disk.py | 4 ++++ archinstall/lib/installer.py | 5 +++-- examples/minimal.py | 4 ++++ 3 files changed, 11 insertions(+), 2 deletions(-) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index f6dc16eb..fe06ac00 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -214,6 +214,10 @@ class Partition(): self._encrypted = value + @property + def parent(self): + return self.real_device + @property def real_device(self): if not self._encrypted: diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 48ef7259..7fd775b1 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -283,8 +283,9 @@ class Installer(): if '/usr/bin/btrfs-progs' not in BINARIES: BINARIES.append('/usr/bin/btrfs') - elif partition.encrypted and 'encrypt' not in HOOKS: - HOOKS.insert(HOOKS.find('filesystems'), 'encrypt') + elif (partition.encrypted or Partition(partition.parent, None).filesystem == 'crypto_LUKS'): + if 'encrypt' not in HOOKS: + HOOKS.insert(HOOKS.find('filesystems'), 'encrypt') self.pacstrap(self.base_packages) self.helper_flags['base-strapped'] = True diff --git a/examples/minimal.py b/examples/minimal.py index 90bd9227..de896d48 100644 --- a/examples/minimal.py +++ b/examples/minimal.py @@ -1,5 +1,9 @@ import archinstall +# Unmount and close previous runs +archinstall.sys_command(f'umount -R /mnt', suppress_errors=True) +archinstall.sys_command(f'cryptsetup close /dev/mapper/luksloop', suppress_errors=True) + # Select a harddrive and a disk password archinstall.log(f"Minimal only supports:") archinstall.log(f" * Being installed to a single disk") -- cgit v1.2.3-54-g00ecf From 8f096001b6f5c8a864bc1e65b56bbfad1a9c9a3f Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 9 Apr 2021 22:34:26 +0200 Subject: Attempting to correct some inconsitencies in disk-parent reporting. --- archinstall/lib/disk.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index fe06ac00..1f0e584a 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -220,12 +220,9 @@ class Partition(): @property def real_device(self): - if not self._encrypted: - return self.path - else: - for blockdevice in json.loads(b''.join(sys_command('lsblk -J')).decode('UTF-8'))['blockdevices']: - if (parent := self.find_parent_of(blockdevice, os.path.basename(self.path))): - return f"/dev/{parent}" + for blockdevice in json.loads(b''.join(sys_command('lsblk -J')).decode('UTF-8'))['blockdevices']: + if (parent := self.find_parent_of(blockdevice, os.path.basename(self.path))): + return f"/dev/{parent}" # raise DiskError(f'Could not find appropriate parent for encrypted partition {self}') return self.path -- cgit v1.2.3-54-g00ecf From e49b73cef41b39e0046a8dc10fddfc4337255a5b Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 9 Apr 2021 23:12:47 +0200 Subject: Attempting to correct some inconsitencies in disk-parent reporting. --- archinstall/lib/disk.py | 3 +++ archinstall/lib/installer.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 1f0e584a..d0d7d4ea 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -166,6 +166,9 @@ class Partition(): self.mountpoint = target if not self.filesystem and autodetect_filesystem: + print(f'Auto-detecting filesystem for: {path}') + print('Mount information:', mount_information.get('fstype', None)) + print('Real device:', get_filesystem_type(self.real_device)) if (fstype := mount_information.get('fstype', get_filesystem_type(self.real_device))): self.filesystem = fstype diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index a60955b7..8adc3515 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -283,7 +283,7 @@ class Installer(): if '/usr/bin/btrfs-progs' not in BINARIES: BINARIES.append('/usr/bin/btrfs') - if (partition.encrypted or Partition(partition.parent, None, autodetect_filesystem=True).filesystem == 'crypto_LUKS'): + if (partition.encrypted or (partition.parent not in partition.path and Partition(partition.parent, None, autodetect_filesystem=True).filesystem == 'crypto_LUKS')): if 'encrypt' not in HOOKS: HOOKS.insert(HOOKS.find('filesystems'), 'encrypt') -- cgit v1.2.3-54-g00ecf From 0531e3a0d6368ee2ae606d2f390ffffaf53e4f2e Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 9 Apr 2021 23:18:04 +0200 Subject: Attempting to correct some inconsitencies in disk-parent reporting. --- 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 d0d7d4ea..15071c00 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -168,8 +168,8 @@ class Partition(): if not self.filesystem and autodetect_filesystem: print(f'Auto-detecting filesystem for: {path}') print('Mount information:', mount_information.get('fstype', None)) - print('Real device:', get_filesystem_type(self.real_device)) - if (fstype := mount_information.get('fstype', get_filesystem_type(self.real_device))): + print('Real device:', get_filesystem_type(path)) + if (fstype := mount_information.get('fstype', get_filesystem_type(path))): self.filesystem = fstype if self.filesystem == 'crypto_LUKS': -- cgit v1.2.3-54-g00ecf From 99c18d5d663453d792683464ce6b077333ec7775 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Fri, 9 Apr 2021 23:26:16 +0200 Subject: Removed some debugging. --- archinstall/lib/disk.py | 3 --- archinstall/lib/installer.py | 1 - 2 files changed, 4 deletions(-) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index 15071c00..e5aa9a85 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -166,9 +166,6 @@ class Partition(): self.mountpoint = target if not self.filesystem and autodetect_filesystem: - print(f'Auto-detecting filesystem for: {path}') - print('Mount information:', mount_information.get('fstype', None)) - print('Real device:', get_filesystem_type(path)) if (fstype := mount_information.get('fstype', get_filesystem_type(path))): self.filesystem = fstype diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index 74978ef6..c4e4e515 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -49,7 +49,6 @@ class Installer(): storage['session'] = self self.partitions = get_partitions_in_use(self.target) - print(self.partitions) def log(self, *args, level=LOG_LEVELS.Debug, **kwargs): """ -- cgit v1.2.3-54-g00ecf From 1e0770e582b8a32175dfda224a153bf19522fb03 Mon Sep 17 00:00:00 2001 From: Anton Hvornum Date: Sat, 10 Apr 2021 10:14:15 +0200 Subject: Modified encrypted partitions to use partuuid for now. --- archinstall/lib/disk.py | 12 ++++++++++++ archinstall/lib/installer.py | 30 ++++++++++++------------------ 2 files changed, 24 insertions(+), 18 deletions(-) (limited to 'archinstall/lib/disk.py') diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py index e5aa9a85..1a2dc4dc 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -126,6 +126,18 @@ class BlockDevice(): def partition_table_type(self): return GPT + @property + def uuid(self): + log(f'BlockDevice().uuid is untested!', level=LOG_LEVELS.Warning, fg='yellow') + """ + Returns the disk UUID as returned by lsblk. + This is more reliable than relying on /dev/disk/by-partuuid as + it doesn't seam to be able to detect md raid partitions. + """ + lsblk = b''.join(sys_command(f'lsblk -J -o+UUID {self.path}')) + for partition in json.loads(lsblk.decode('UTF-8'))['blockdevices']: + return partition.get('uuid', None) + def has_partitions(self): return len(self.partitions) diff --git a/archinstall/lib/installer.py b/archinstall/lib/installer.py index af973227..0c622129 100644 --- a/archinstall/lib/installer.py +++ b/archinstall/lib/installer.py @@ -257,7 +257,12 @@ class Installer(): return True def detect_encryption(self, partition): - return partition.encrypted or (partition.parent not in partition.path and Partition(partition.parent, None, autodetect_filesystem=True).filesystem == 'crypto_LUKS') + if partition.encrypted: + return partition + elif partition.parent not in partition.path and Partition(partition.parent, None, autodetect_filesystem=True).filesystem == 'crypto_LUKS': + return Partition(partition.parent, None, autodetect_filesystem=True) + + return False def minimal_installation(self): ## Add necessary packages if encrypting the drive @@ -375,26 +380,15 @@ class Installer(): ## so we'll use the old manual method until we get that sorted out. - if self.detect_encryption(root_partition): - log(f"Identifying root partition by DISK-UUID on {root_partition}, looking for '{os.path.basename(root_partition.real_device)}'.", level=LOG_LEVELS.Debug) - for root, folders, uids in os.walk('/dev/disk/by-uuid'): - for uid in uids: - real_path = os.path.realpath(os.path.join(root, uid)) - - log(f"Checking root partition match {os.path.basename(real_path)} against {os.path.basename(root_partition.real_device)}: {os.path.basename(real_path) == os.path.basename(root_partition.real_device)}", level=LOG_LEVELS.Debug) - if not os.path.basename(real_path) == os.path.basename(root_partition.real_device): continue - - entry.write(f'options cryptdevice=UUID={uid}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n') - - self.helper_flags['bootloader'] = bootloader - return True - break + if (real_device := self.detect_encryption(root_partition)): + log(f"Identifying root partition by PART-UUID on {real_device}: '{real_device.uuid}'.", level=LOG_LEVELS.Debug) + entry.write(f'options cryptdevice=PARTUUID={real_device.uuid}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n') else: - log(f"Identifying root partition by PART-UUID on {root_partition}, looking for '{os.path.basename(root_partition.path)}'.", level=LOG_LEVELS.Debug) + log(f"Identifying root partition by PART-UUID on {root_partition}, looking for '{root_partition.uuid}'.", level=LOG_LEVELS.Debug) entry.write(f'options root=PARTUUID={root_partition.uuid} rw intel_pstate=no_hwp\n') - self.helper_flags['bootloader'] = bootloader - return True + self.helper_flags['bootloader'] = bootloader + return True raise RequirementError(f"Could not identify the UUID of {root_partition}, there for {self.target}/boot/loader/entries/arch.conf will be broken until fixed.") else: -- cgit v1.2.3-54-g00ecf From a7b01aa29e38a2faf88f04b7df7dcb4ee8545d90 Mon Sep 17 00:00:00 2001 From: Dylan Taylor Date: Sat, 10 Apr 2021 11:11:09 -0400 Subject: Show size in partition string representation --- 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 1a2dc4dc..bada4076 100644 --- a/archinstall/lib/disk.py +++ b/archinstall/lib/disk.py @@ -199,9 +199,9 @@ class Partition(): mount_repr = f", rel_mountpoint={self.target_mountpoint}" if self._encrypted: - return f'Partition(path={self.path}, real_device={self.real_device}, fs={self.filesystem}{mount_repr})' + return f'Partition(path={self.path}, size={self.size}, real_device={self.real_device}, fs={self.filesystem}{mount_repr})' else: - return f'Partition(path={self.path}, fs={self.filesystem}{mount_repr})' + return f'Partition(path={self.path}, size={self.size}, fs={self.filesystem}{mount_repr})' @property def uuid(self) -> str: -- cgit v1.2.3-54-g00ecf