Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/archinstall/lib
diff options
context:
space:
mode:
authorAnton Hvornum <anton.feeds@gmail.com>2021-03-09 11:48:40 +0100
committerAnton Hvornum <anton.feeds@gmail.com>2021-03-09 11:48:40 +0100
commit9f0d25bce302459efa5ab5b9eaf22bb1f1feb575 (patch)
tree5721a2b6f88bcc24b7ca15e89cf57dce176a3652 /archinstall/lib
parent586f8bc32ef81695f31f10f41472443ad5f280cd (diff)
Added functions to auto-detect filesystems inside encrypted partitions (given a password)
Diffstat (limited to 'archinstall/lib')
-rw-r--r--archinstall/lib/disk.py5
-rw-r--r--archinstall/lib/luks.py9
2 files changed, 12 insertions, 2 deletions
diff --git a/archinstall/lib/disk.py b/archinstall/lib/disk.py
index 335ec42e..75cecb0b 100644
--- a/archinstall/lib/disk.py
+++ b/archinstall/lib/disk.py
@@ -188,6 +188,11 @@ class Partition():
return f"/dev/{parent}"
raise DiskError(f'Could not find appropriate parent for encrypted partition {self}')
+ def detect_inner_filesystem(self, password):
+ from .luks import luks2
+ with luks2(self, 'luksloop', password, auto_unmount=True) as unlocked_device:
+ return unlocked_device.filesystem
+
def has_content(self):
temporary_mountpoint = '/tmp/'+hashlib.md5(bytes(f"{time.time()}", 'UTF-8')+os.urandom(12)).hexdigest()
temporary_path = pathlib.Path(temporary_mountpoint)
diff --git a/archinstall/lib/luks.py b/archinstall/lib/luks.py
index c9946239..fa040788 100644
--- a/archinstall/lib/luks.py
+++ b/archinstall/lib/luks.py
@@ -6,13 +6,14 @@ from .output import log, LOG_LEVELS
from .storage import storage
class luks2():
- def __init__(self, partition, mountpoint, password, key_file=None, *args, **kwargs):
+ def __init__(self, partition, mountpoint, password, key_file=None, auto_unmount=False, *args, **kwargs):
self.password = password
self.partition = partition
self.mountpoint = mountpoint
self.args = args
self.kwargs = kwargs
self.key_file = key_file
+ self.auto_unmount = auto_unmount
self.filesystem = 'crypto_LUKS'
def __enter__(self):
@@ -32,6 +33,9 @@ class luks2():
def __exit__(self, *args, **kwargs):
# TODO: https://stackoverflow.com/questions/28157929/how-to-safely-handle-an-exception-inside-a-context-manager
+ if self.auto_unmount:
+ self.close()
+
if len(args) >= 2 and args[1]:
raise args[1]
return True
@@ -73,11 +77,12 @@ class luks2():
:param mountpoint: The name without absolute path, for instance "luksdev" will point to /dev/mapper/luksdev
:type mountpoint: str
"""
+ from .disk import get_filesystem_type
if '/' in mountpoint:
os.path.basename(mountpoint) # TODO: Raise exception instead?
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}'):
- return Partition(f'/dev/mapper/{mountpoint}', encrypted=True)
+ return Partition(f'/dev/mapper/{mountpoint}', encrypted=True, filesystem=get_filesystem_type(f'/dev/mapper/{mountpoint}'))
def close(self, mountpoint):
sys_command(f'cryptsetup close /dev/mapper/{mountpoint}')