diff --git a/archinstall/__init__.py b/archinstall/__init__.py index bf09b188..44ccf1dd 100644 --- a/archinstall/__init__.py +++ b/archinstall/__init__.py @@ -72,6 +72,9 @@ def define_arguments(): parser.add_argument("--script", default="guided", nargs="?", help="Script to run for installation", type=str) parser.add_argument("--mount-point","--mount_point", nargs="?", type=str, help="Define an alternate mount point for installation") parser.add_argument("--debug", action="store_true", default=False, help="Adds debug info into the log") + parser.add_argument("--crypt-iter-time", default='10000', nargs="?", type=str) + parser.add_argument("--crypt-key-size", default='512', nargs="?", type=str) + parser.add_argument("--crypt-hash-type", default='sha512', nargs="?", type=str) parser.add_argument("--plugin", nargs="?", type=str) def parse_unspecified_argument_list(unknowns :list, multiple :bool = False, error :bool = False) -> dict: diff --git a/archinstall/lib/disk/btrfs.py b/archinstall/lib/disk/btrfs.py index f2da957f..6ab720a0 100644 --- a/archinstall/lib/disk/btrfs.py +++ b/archinstall/lib/disk/btrfs.py @@ -3,13 +3,13 @@ import pathlib import glob import logging import re -from typing import Union, Dict, TYPE_CHECKING, Any, Iterator +from typing import Union, Dict, TYPE_CHECKING, Any, Iterator, Optional from dataclasses import dataclass # https://stackoverflow.com/a/39757388/929999 if TYPE_CHECKING: from ..installer import Installer -from .helpers import get_mount_info +from .helpers import get_mount_info, get_mount_fs_type from ..exceptions import DiskError from ..general import SysCommand from ..output import log @@ -24,6 +24,37 @@ class BtrfsSubvolume: options :str root :bool = False + @property + def MapperDev(self): + return self._mapperdev + + def mount(self, target :str, fs :Optional[str] = None, options :str = '') -> bool: + log(f'Mounting {self} to {target}', level=logging.INFO) + if not fs: + if not self.MapperDev.filesystem: + raise DiskError(f'Need to format (or define) the filesystem on {self} before mounting.') + fs = self.MapperDev.filesystem + + fs_type = get_mount_fs_type(fs) + + pathlib.Path(target).mkdir(parents=True, exist_ok=True) + + # TODO: Detect if destination is already mounted some how. + # Otherwise we won't be able to mount the subvolume. + + # TODO options should be better be a list than a string + if options: + options = f"{options},subvol={self.name}" + else: + options = f"subvol={self.name}" + + try: + SysCommand(f"/usr/bin/mount -t {fs_type} -o {options} {self.MapperDev.path} {target}") + except SysCallError as err: + raise DiskError(f"Could not mount {self.path} to {target} using options {options}: {err}") + + return True + def get_subvolumes_from_findmnt(struct :Dict[str, Any], index=0) -> Iterator[BtrfsSubvolume]: if '@' in struct['source']: subvolume = re.findall(r'\[.*?\]', struct['source'])[0][1:-1] diff --git a/archinstall/lib/disk/filesystem.py b/archinstall/lib/disk/filesystem.py index a225171d..accfea65 100644 --- a/archinstall/lib/disk/filesystem.py +++ b/archinstall/lib/disk/filesystem.py @@ -123,7 +123,12 @@ class Filesystem: else: loopdev = f"{storage.get('ENC_IDENTIFIER', 'ai')}{pathlib.Path(partition['device_instance'].path).name}" - partition['device_instance'].encrypt(password=partition['!password']) + partition['device_instance'].encrypt( + password=partition['!password'], + key_size=storage['arguments']['crypt-key-size'], + hash_type=storage['arguments']['crypt-hash-type'], + iter_time=storage['arguments']['crypt-iter-time'] + ) # Immediately unlock the encrypted device to format the inner volume with luks2(partition['device_instance'], loopdev, partition['!password'], auto_unmount=True) as unlocked_device: if not partition.get('wipe'): diff --git a/archinstall/lib/disk/mapperdev.py b/archinstall/lib/disk/mapperdev.py index 340b3ea4..77b12e37 100644 --- a/archinstall/lib/disk/mapperdev.py +++ b/archinstall/lib/disk/mapperdev.py @@ -5,7 +5,7 @@ import json from dataclasses import dataclass from typing import Optional, List, Dict, Any, Iterator, TYPE_CHECKING -from ..exceptions import SysCallError +from ..exceptions import SysCallError, DiskError from ..general import SysCommand from ..output import log @@ -103,12 +103,10 @@ class MapperDev: try: if options: - mnt_handle = SysCommand(f"/usr/bin/mount -t {fs_type} -o {options} {self.path} {target}") + SysCommand(f"/usr/bin/mount -t {fs_type} -o {options} {self.path} {target}") else: - mnt_handle = SysCommand(f"/usr/bin/mount -t {fs_type} {self.path} {target}") - + SysCommand(f"/usr/bin/mount -t {fs_type} {self.path} {target}") except SysCallError as err: raise DiskError(f"Could not mount {self.path} to {target} using options {options}: {err}") - return True - + return True \ No newline at end of file diff --git a/archinstall/lib/luks.py b/archinstall/lib/luks.py index 16ef9554..5ad0130b 100644 --- a/archinstall/lib/luks.py +++ b/archinstall/lib/luks.py @@ -107,7 +107,7 @@ class luks2: pw_given = False while cryptworker.is_alive(): - if bytes(f'Enter passphrase for {partition.path}', 'UTF-8') in cryptworker and pw_given is False: + if bytes(f'Enter passphrase for {partition.path}', 'UTF-8') in cryptworker._trace_log and pw_given is False: cryptworker.write(password) pw_given = True @@ -186,7 +186,7 @@ class luks2: pw_given = False while cryptworker.is_alive(): - if bytes(f'Enter passphrase for {partition.path}', 'UTF-8') in cryptworker and pw_given is False: + if bytes(f'Enter passphrase for {partition.path}', 'UTF-8') in cryptworker._trace_log and pw_given is False: cryptworker.write(password) pw_given = True