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.

This commit is contained in:
Anton Hvornum 2020-07-08 16:12:57 +00:00
parent 078567f81c
commit c271e4c0d7
2 changed files with 25 additions and 4 deletions

View File

@ -88,7 +88,10 @@ class Partition():
self.encrypted = encrypted self.encrypted = encrypted
def __repr__(self, *args, **kwargs): 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): def format(self, filesystem):
log(f'Formatting {self} -> {filesystem}') log(f'Formatting {self} -> {filesystem}')
@ -110,6 +113,24 @@ class Partition():
raise DiskError(f'Fileformat {filesystem} is not yet implemented.') raise DiskError(f'Fileformat {filesystem} is not yet implemented.')
return True 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=''): def mount(self, target, fs=None, options=''):
if not self.mountpoint: if not self.mountpoint:
log(f'Mounting {self} to {target}') log(f'Mounting {self} to {target}')

View File

@ -63,11 +63,11 @@ class Installer():
if self.partition.encrypted: if self.partition.encrypted:
print(f'Trying to locate {os.path.basename(self.partition.path)} under /dev/disk/by-partuuid') print(f'Trying to locate {self.partition} under /dev/disk/by-partuuid')
for root, folders, uids in os.walk('/dev/disk/by-partuuid'): for root, folders, uids in os.walk('/dev/disk/by-partuuid'):
for uid in uids: for uid in uids:
real_path = os.path.realpath(os.path.join(root, uid)) real_path = os.path.realpath(os.path.join(root, uid))
if not os.path.basename(real_path) == os.path.basename(self.partition.path): continue if not os.path.basename(real_path) == os.path.basename(self.partition.real_device): continue
entry.write(f'options cryptdevice=PARTUUID={uid}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n') entry.write(f'options cryptdevice=PARTUUID={uid}:luksdev root=/dev/mapper/luksdev rw intel_pstate=no_hwp\n')
return True return True