Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib/disk.py
diff options
context:
space:
mode:
authorAnton Hvornum <anton.feeds+github@gmail.com>2020-07-08 16:12:57 +0000
committerAnton Hvornum <anton.feeds+github@gmail.com>2020-07-08 16:12:57 +0000
commitc271e4c0d7f15c13fe056d80f1b652b6eebde21a (patch)
tree3c9dee70d4a7882fc51f01060ae06191822530d2 /archinstall/lib/disk.py
parent078567f81c17492d0f3bc857a6efa09cc3503fa5 (diff)
Added a encrypted flag to the Partition() object. So that certain checks can be done by the Installer() later on, for instance when adding a bootloader. There's also a now which tries to find the parent device to the unlocked encrypted device.
Diffstat (limited to 'archinstall/lib/disk.py')
-rw-r--r--archinstall/lib/disk.py25
1 files changed, 23 insertions, 2 deletions
diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py
index 30dbcdc2..c6fba8ce 100644
--- a/archinstall/lib/disk.py
+++ b/archinstall/lib/disk.py
@@ -88,7 +88,10 @@ class Partition():
self.encrypted = encrypted
def __repr__(self, *args, **kwargs):
- return f'Partition({self.path}, fs={self.filesystem}, mounted={self.mountpoint})'
+ if self.encrypted:
+ return f'Partition(path={self.path}, real_device={self.real_device}, fs={self.filesystem}, mounted={self.mountpoint})'
+ else:
+ return f'Partition(path={self.path}, fs={self.filesystem}, mounted={self.mountpoint})'
def format(self, filesystem):
log(f'Formatting {self} -> {filesystem}')
@@ -110,6 +113,24 @@ class Partition():
raise DiskError(f'Fileformat {filesystem} is not yet implemented.')
return True
+ def find_parent_of(self, data, name, parent=None):
+ if data['name'] == name:
+ return parent
+ elif 'children' in data:
+ for child in data['children']:
+ if (parent := self.find_parent_of(child, name, parent=data['name'])):
+ return parent
+
+ @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}"
+ raise DiskError(f'Could not find appropriate parent for encrypted partition {self}')
+
def mount(self, target, fs=None, options=''):
if not self.mountpoint:
log(f'Mounting {self} to {target}')
@@ -124,7 +145,7 @@ class Partition():
if sys_command(f'/usr/bin/mount {self.path} {target}').exit_code == 0:
self.mountpoint = target
return True
-
+
class Filesystem():
# TODO:
# When instance of a HDD is selected, check all usages and gracefully unmount them